-
Notifications
You must be signed in to change notification settings - Fork 0
/
regs.h
135 lines (115 loc) · 4.86 KB
/
regs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifndef __REGS_H__
#define __REGS_H__
//
// Bootloader registers
//
enum boot_regs_type {
BOOT_REG_ID,
BOOT_REG_LEVEL,
BOOT_REG_STATUS,
BOOT_REG_CMD,
BOOT_REG_ADDR,
BOOT_REG_DATA,
BOOT_REG_END,
BOOT_NUM_REGS
};
enum boot_command_type {
BOOT_CMD_NOP = 0,
BOOT_CMD_PAGE_ERASE,
BOOT_CMD_FULL_ERASE,
BOOT_CMD_HALF_PAGE_PROG,
BOOT_CMD_EXECUTE,
BOOT_CMD_ERROR = 0xEE,
};
//
// Firmware version is tied to registers and commands
//
#define FIRMWARE_MAJOR 1
#define FIRMWARE_MINOR 0
enum registers_type {
REG_ID, // 00 - 0xED for all new AndiceLabs products
REG_PROD, // 01 - Product ID/type
REG_STEP, // 02 - Product stepping: P=0,A=1,B=2 - significant HW changes
REG_REVISION, // 03 - Product revision: small HW changes (BOM only)
REG_VERSION_MAJOR, // 04 - Firmware major version
REG_VERSION_MINOR, // 05 - Firmware minor version
REG_RESET_FLAGS, // 06 - MCU reset flags
REG_STATUS, // 07 - Board status flags (button state, power good, armed WDTs, etc.)
REG_CONTROL, // 08 - Control flags (charge enable, AUX output, etc.)
REG_START_ENABLE, // 09 -
REG_START_REASON, // 0A -
REG_DATA_0, // 0B - Command LSB data
REG_DATA_1, // 0C -
REG_DATA_2, // 0D -
REG_DATA_3, // 0E - Command MSB data
REG_COMMAND, // 0F - Command register
REG_WDT_POWER, // 10 - Power-cycle watchdog countdown register (seconds, 0 to disable)
REG_WDT_STOP, // 11 - Power-off countdown (single-shot seconds, 0 to disable)
REG_WDT_START, // 12 - Start-up activity watchdog countdown (seconds, 0 to disable)
REG_END, // 14 - 0xEE
NUM_REGISTERS
};
// REG_ID is always 0xED (I miss you, Dad!)
// REG_PROD types
#define PROD_UNKNOWN 0x00 // MFG unprogrammed
#define PROD_POWERCAPE 0x01 // VCC is tied to 3v3
#define PROD_POWERHAT 0x02 // VCC is tied to GPIO26 for shutdown request
#define PROD_POWERMODULE 0x03 // Aux power, no charger, Grove interface
// REG_STATUS bits
#define STATUS_POWER_GOOD 0x01 // PG state
#define STATUS_BUTTON 0x02 // Button state
#define STATUS_OPTO 0x04 // Opto state
#define STATUS_LED 0x08 // LED state
#define STATUS_EXT_POWER 0x10 // External power state
#define STATUS_FLASH_LOCK 0x20 //
#define STATUS_MFG_LOCK 0x40 //
#define STATUS_BOOTLOADER 0x80 // Capability
// REG_CONTROL
#define CONTROL_AUX_OUTPUT 0x01
#define CONTROL_LED 0x02
#define CONTROL_CHARGE_ENABLE 0x04
#define CONTROL_IGNORE_POWEROFF 0x08
// START_ENABLE and START_REASON register bits
#define START_BUTTON 0x01 // External (power) button
#define START_EXTERNAL 0x02 // External (opto) signal
#define START_PWRGOOD 0x04 // DC power for battery charger products
#define START_TIMEOUT 0x08 // Countdown timeout
#define START_PWR_ON 0x10 // Initial application of power
#define START_WDT_RESET 0x20 // WDT cycled power
#define START_ALL 0x1F
// ====================
// REG_COMMAND commands
// --------------------
// Self-test, set NVRAM defaults, lock device, set RTC, etc.
#define COMMAND_CHARGE_ENABLE 0x10
#define COMMAND_CHARGE_DISABLE 0x11
#define COMMAND_LED_ON_MS 0x12
#define COMMAND_LED_OFF_MS 0x13
#define COMMAND_EXT_PWR_ON 0x14
#define COMMAND_EXT_PWR_OFF 0x15
#define COMMAND_SET_RESTART_TIME 0x16
#define COMMAND_GET_RESTART_TIME 0x17
#define COMMAND_CLEAR_RESTART_TIME 0x18
#define COMMAND_GET_ONTIME 0x19
#define COMMAND_GET_OFFTIME 0x1A
#define COMMAND_GET_CHARGE_RATE 0x1B
#define COMMAND_SET_CHARGE_RATE_1 0x1C
#define COMMAND_SET_CHARGE_RATE_2 0x1D
#define COMMAND_SET_CHARGE_RATE_3 0x1E
#define COMMAND_FIRMWARE_TIMESTAMP 0x1F
#define COMMAND_READ_COUNT 0x20
#define COMMAND_WRITE_COUNT 0x21
#define COMMAND_SET_I2C_ADDRESS 0x22
#define COMMAND_SET_RTC_ADDRESS 0x23
#define COMMAND_DISARM_VCC 0x24 // ignore VCC or GPIO26
#define COMMAND_ARM_VCC 0x25
#define COMMAND_LOADER_TIMESTAMP 0x2F
#define COMMAND_GET_RTC_CAL 0x30
#define COMMAND_SET_RTC_CAL 0x31
#define COMMAND_GET_TIMESTAMP 0x32
#define COMMAND_GET_SERIAL 0x33
#define COMMAND_EEPROM_CLEAR 0x3C
#define COMMAND_EEPROM_STORE 0x3E
#define COMMAND_REBOOT 0xBB
#define COMMAND_ENTER_BOOTLOADER 0xEB
#endif // __REGS_H__