tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/l3gd20/l3gd20.go (about)

     1  package l3gd20
     2  
     3  import "errors"
     4  
     5  var (
     6  	ErrBadIdentity = errors.New("got unexpected identity from WHOMAI")
     7  	ErrBadRange    = errors.New("bad range configuration value")
     8  )
     9  
    10  // Sensitivity factors
    11  const (
    12  	// range at bits 4-5
    13  	// 00 = 250 dps
    14  	// 01 = 500 dps
    15  	// 10 = 2000 dps
    16  	// 11 = 2000 dps
    17  	rangePos   = 4
    18  	Range_250  = 0b00 << rangePos // 8.75 mdps/digit
    19  	Range_500  = 0b01 << rangePos // 17.5 mdps/digit
    20  	Range_2000 = 0b11 << rangePos // 70 mdps/digit
    21  	rangebits  = Range_250 | Range_500 | Range_2000
    22  
    23  	// Sensitivities for degrees
    24  	sensDiv250dps  = 800
    25  	sensDiv500dps  = 400
    26  	sensDiv2000dps = 100
    27  	sens_250       = 7. / sensDiv250dps  // Sensitivity at 250 dps
    28  	sens_500       = 7. / sensDiv500dps  // Sensitivity at 500 dps
    29  	sens_2000      = 7. / sensDiv2000dps // Sensitivity at 500 dp
    30  
    31  	// 1e6*Pi/180. = 17453.292519943298 (constant for Degree to micro radians conversion)
    32  	// sensitivities for radians
    33  	sensMul250  = 7 * 1745329 / 100 / sensDiv250dps
    34  	sensMul500  = 7 * 1745329 / 100 / sensDiv500dps
    35  	sensMul2000 = 7 * 1745329 / 100 / sensDiv2000dps
    36  )
    37  
    38  type Config struct {
    39  	Range uint8
    40  }
    41  
    42  // validate scans config for invalid data and returns non-nil
    43  // error indicating what data must be modified.
    44  func (cfg *Config) validate() error {
    45  	if cfg.Range&^rangebits != 0 && cfg.Range != 1 {
    46  		return ErrBadRange
    47  	}
    48  	return nil
    49  }