How does auto-trim work on fly-by-wire aircraft? As I understand, you trim to reduce the effort needed to maintain the stick in the right position. Thus, you may reach steady flight before moving the trimming wheel.

In fly-by-wire aircraft (to fix things, let's consider an A320), there is no such effort to maintain as you use sidesticks. Moreover the elevator may move almost constantly (and thus always apply some effort) to compensate turbulence (enhance stability feature).

After reading this question, I understand that trim is achieved by moving the stabilizator and that in normal law it is done by the computer (we actually see the trim wheel moving alone)

My question comes in several parts:


In flight in normal law, how and when does the computer decide it must trim the plane? 
What does it take into account to trim the plane (speed? flaps configuration? average position of the elevators for the last few seconds? a mix of all? I guess average position of the elevator in a sliding time window is enough)
Does it anticipate the trim (e.g. trim before or while changing the flaps configuration)?
What happen on the ground? For example during the take off roll, I don't think there is enough data to feed an auto-trim system, but I may be mistaken.
What happen if not in normal law (I guess auto-trim would be one of the feature unavailable in alternate law)?


EDIT: althought the question may seem similar to this one, it differs as my question address the decision process used by the auto-trim system to command the flight control surface, and not the flight control surface itself (the use of stabilisator as trim in the A320)
In fly-by-wire aircraft (to fix things, let's consider an A320), there is no such effort to maintain as you use sidesticks.


Let's be clear: there is no such effort on the pilot side, but the forces on the surfaces are still there and are taken care of by the electro-hydraulic actuators.


  
  In flight in normal law, how and when does the computer decide it must trim the plane? 
  What does it take into account to trim the plane?
  


I will answer these two together. And let's remember what written above: the actuators are taking care of the control surfaces loads, this means that part of the actuator authority is being used to control a static load.

In an ideal situation all the authority (coming from hydraulic pressure or coil current) can be dedicated to control transients: gusts, configuration changes, turn entering, turn leaving. If you are allocating part of this authority to keep level flight, a gust (for example) that otherwise would have been easily compensated for, will lead to a momentarily loss of coordination, reducing the comfort of the passengers.

That is what (mostly) you use to trim the aircraft: if your actuator is constantly (or on average over several seconds) applying a certain force in a certain direction, the system will use the trim functionality to remove said force while not altering the flight equilibrium.


  
  Does it anticipate the trim?
  


I have no public reference for this.


  
  What happen on the ground?
  


Usually you leave the aircraft with no trim.


  
  What happen if not in normal law (I guess auto-trim would be one of the feature unavailable in alternate law)?
  


Unless you are outside of normal law for actuator-related issues (power/hydraulic losses, for example) I see no reason why trimming would be unavailable, all that is required for trimming, as said above, is the average load on the actuators and trimming actuation capabilities.