tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/as560x/registers.go (about) 1 package as560x // import tinygo.org/x/drivers/ams560x 2 3 // DefaultAddress is the default I2C address of the AMS AS560x sensors (0x36). 4 const DefaultAddress uint8 = 0x36 5 6 // AS560x common device registers 7 const ( 8 // ZMCO contains the number of times a BURN_ANGLE command has been executed (max 3 burns) 9 ZMCO = 0x00 10 // ZPOS is the zero (start) position in RAW_ANGLE terms. 11 ZPOS = 0x01 12 // CONF supports custom config. Raw 14-bit register. See datasheet for mapping or use 'virtual registers' below. 13 CONF = 0x07 14 // STATUS indicates magnet position. Encapsulates MD, ML & MH. See also 'virtual registers' below. 15 STATUS = 0x0b 16 // RAW_ANGLE is the raw unscaled & unadjusted angle (12 bit: 0-4095/0xfff) 17 RAW_ANGLE = 0x0c 18 // ANGLE is RAW_ANGLE scaled & adjusted according to ZPOS (and MPOS/MANG on AS5600). (12 bit: 0-4095/0xfff) 19 ANGLE = 0x0e 20 // AGC is the Automatic Gain Control based on temp, airgap etc. 0-255 @ 5V, 0-128 @ 3.3V. 21 AGC = 0x1a 22 // MAGNITUDE indicates the magnitude value of the internal CORDIC output. See datasheet for more info. 23 MAGNITUDE = 0x1b 24 // BURN performs permanent programming of some registers. See BURN_XYZ cmd constants below for commands. 25 BURN = 0xff 26 ) 27 28 // AS5600 specific registers 29 const ( 30 // MPOS is the maximum position in RAW_ANGLE terms. With ZPOS, defines a 'narrower angle' for higher resolution. 31 MPOS = 0x03 32 // MANG is the maximum angle. With ZPOS, defines a 'narrower angle' for higher resolution. 33 MANG = 0x05 34 ) 35 36 // AS5601 specific registers 37 const ( 38 // ABN. See datasheet for mapping 39 ABN = 0x09 40 // PUSHTHR. Configures push-button function. See datasheet and AGC 41 PUSHTHR = 0x0a 42 ) 43 44 // 'Virtual Registers' (VRs) are bitfields within the registers above. 45 // These are not real register addresses recognized by the chip, 46 // but they are recognized by the driver for convenience. 47 48 // virtualRegisterStartAddress defines the start of the virtual register address range. 49 const virtualRegisterStartAddress = 0xa0 50 51 const ( 52 // VRs for CONF 53 54 // WD is a Virtual Register for the Watchdog timer. See WATCHDOG_TIMER consts. 55 WD = iota + virtualRegisterStartAddress 56 // FTH is a Virtual Register for the Fast Filter Threshold. See FAST_FILTER_THRESHOLD consts. 57 FTH 58 // SF is a Virtual Register for the Slow Filter. See SLOW_FILTER_RESPONSE consts. 59 SF 60 // PWMF is a Virtual Register for PWM Frequency (AS5600 ONLY). See PWM_FREQUENCY consts. 61 PWMF 62 // OUTS is a Virtual Register for the Output Stage (AS5600 ONLY). See OUTPUT_STAGE consts. 63 OUTS 64 // HYST is a Virtual Register for Hysteresis. See HYSTERESIS consts. 65 HYST 66 // PM is a Virtual Register for the Power Mode. See POWER_MODE consts. 67 PM 68 69 // VRs for STATUS (0 = unset, 1 = set) 70 71 // MD is a Virtual Register for the 'Magnet was detected' flag. 72 MD 73 // ML is a Virtual Register for the 'AGC maximum gain overflow' a.k.a 'magnet too weak' flag. 74 ML 75 // MH is a Virtual Register for the 'AGC minimum gain overflow' a.k.a 'magnet too strong' flag. 76 MH 77 ) 78 79 // POWER_MODE values for the PM component of CONF (and the PM VR) 80 const ( 81 // PM_NOM is the normal 'always on' power mode. No polling, max 6.5mA current 82 PM_NOM = iota 83 // PM_LPM1 is Low Power Mode 1. 5ms polling, max 3.4mA current 84 PM_LPM1 85 // PM_LPM2 is Low Power Mode 2. 20ms polling, max 1.8mA current 86 PM_LPM2 87 // PM_LPM3 is Low Power Mode 3. 100ms polling, max 1.5mA current 88 PM_LPM3 89 ) 90 91 // HYSTERESIS values for the HYST component of CONF (and the HYST VR) 92 const ( 93 // HYST_OFF disables any hysteresis of the output 94 HYST_OFF = iota 95 // HYST_1LSB enables output hysteresis using 1 LSB 96 HYST_1LSB 97 // HYST_2LSB enables output hysteresis using 2 LSBs 98 HYST_2LSB 99 // HYST_3LSB enables output hysteresis using 3 LSBs 100 HYST_3LSB 101 ) 102 103 // OUTPUT_STAGE values for the OUTS component of CONF (and the OUTS VR - AS5600 ONLY) 104 const ( 105 // OS_ANALOG_FULL_RANGE enables analog output with full range (0%-100% VDD) 106 OS_ANALOG_FULL_RANGE = iota 107 // OS_ANALOG_REDUCED_RANGE enables analog output with reduced range (10%-90% VDD) 108 OS_ANALOG_REDUCED_RANGE 109 // OS_DIGITAL_PWM enables digital PWM output. Frequency determined by PWMF 110 OS_DIGITAL_PWM 111 ) 112 113 // PWM_FREQUENCY values for the PWMF component of CONF (and the PWMF VR - ASS5600 ONLY) 114 const ( 115 // PWMF_115_HZ enables PWM at 115 Hz 116 PWMF_115_HZ = iota 117 // PWMF_230_HZ enables PWM at 230 Hz 118 PWMF_230_HZ 119 // PWMF_460_HZ enables PWM at 460 Hz 120 PWMF_460_HZ 121 // PWMF_920_HZ enables PWM at 920 Hz 122 PWMF_920_HZ 123 ) 124 125 // SLOW_FILTER_RESPONSE values for the SF (slow filter) component of CONF (and the SF VR) 126 const ( 127 // SF_16X enables a 16x Slow Filter step response 128 SF_16X = iota 129 // SF_8X enables a 8x Slow Filter step response 130 SF_8X 131 // SF_4X enables a 4x Slow Filter step response 132 SF_4X 133 // SF_2X enables a 2x Slow Filter step response 134 SF_2X 135 ) 136 137 // FAST_FILTER_THRESHOLD values for the FTH (fast filter threshold) component of CONF (and the FTH VR) 138 const ( 139 // FTH_NONE disables the fast filter (slow filter only) 140 FTH_NONE = iota 141 // FTH_6LSB enables a fast filter threshold with 6 LSBs 142 FTH_6LSB 143 // FTH_7LSB enables a fast filter threshold with 7 LSBs 144 FTH_7LSB 145 // FTH_9LSB enables a fast filter threshold with 9 LSBs 146 FTH_9LSB 147 // FTH_18LSB enables a fast filter threshold with 18 LSBs 148 FTH_18LSB 149 // FTH_21LSB enables a fast filter threshold with 21 LSBs 150 FTH_21LSB 151 // FTH_24LSB enables a fast filter threshold with 24 LSBs 152 FTH_24SB 153 // FTH_10LSB enables a fast filter threshold with 10 LSBs 154 FTH_10LSB 155 ) 156 157 // WATCHDOG_TIMER values for the WD component of CONF (and the WD VR) 158 const ( 159 // WD_OFF disables the Watchdog Timer 160 WD_OFF = iota 161 // WD_ON enables the Watchdog Timer (automatic entry into LPM3 low-power mode enabled) 162 WD_ON 163 ) 164 165 // constants for the raw STATUS register bitfield value. 166 const ( 167 // STATUS_MH is set in STATUS when the magnet field is too strong (AGC minimum gain overflow) 168 STATUS_MH = 1 << (iota + 3) 169 // STATUS_ML is set in STATUS when the magnet field is too weak (AGC maximum gain overflow) 170 STATUS_ML 171 // STATUS_MD is set n STATUS when the magnet is detected. Doesn't seem to work with some units. 172 STATUS_MD 173 ) 174 175 // ABN_MAPPING values for the ABN register (AS5601 ONLY) 176 const ( 177 // ABN_8 configures 8 output positions (61 Hz) 178 ABN_8 = iota 179 // ABN_16 configures 16 output positions (122 Hz) 180 ABN_16 181 // ABN_32 configures 32 output positions (244 Hz) 182 ABN_32 183 // ABN_64 configures 64 output positions (488 Hz) 184 ABN_64 185 // ABN_128 configures 128 output positions (976 Hz) 186 ABN_128 187 // ABN_256 configures 256 output positions (1.95 KHz) 188 ABN_256 189 // ABN_512 configures 512 output positions (3.9 KHz) 190 ABN_512 191 // ABN_1024 configures 1024 output positions (7.8 KHz) 192 ABN_1024 193 // ABN_2048 configures 2048 output positions (15.6 KHz) 194 ABN_2048 195 ) 196 197 // BURN_CMD is a command to write to the BURN register. 198 type BURN_CMD uint16 199 200 const ( 201 // BURN_ANGLE is the value to write to BURN to permanently program ZPOS & MPOS (Max 3 times!) 202 BURN_ANGLE BURN_CMD = 0x80 203 // BURN_SETTING is the value to write to BURN to permanently program MANG & CONF (ONCE ONLY!) 204 BURN_SETTING BURN_CMD = 0x40 205 ) 206 207 // BURN_ANGLE_COUNT_MAX is a constant for the maximum number of times a BURN_ANGLE command can be executed. Compare this with ZMCO 208 const BURN_ANGLE_COUNT_MAX uint16 = 3