AE11 GUI for PICO
Dependencies: max32625pico USBDevice
main.cpp@0:a13d6826cf66, 2020-06-25 (annotated)
- Committer:
- PowerIC
- Date:
- Thu Jun 25 17:25:24 2020 +0000
- Revision:
- 0:a13d6826cf66
Initial_Upload
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
PowerIC | 0:a13d6826cf66 | 1 | /////////////////////////////////////////////////////////////////////////////////////////////////////// |
PowerIC | 0:a13d6826cf66 | 2 | // MAX32625PICO FIRMWARE FOR MAXIM AE11 EVBs |
PowerIC | 0:a13d6826cf66 | 3 | // Revision: 1.3 |
PowerIC | 0:a13d6826cf66 | 4 | // Date: 09/18/2019 |
PowerIC | 0:a13d6826cf66 | 5 | // Author: Bill Smith |
PowerIC | 0:a13d6826cf66 | 6 | /////////////////////////////////////////////////////////////////////////////////////////////////////// |
PowerIC | 0:a13d6826cf66 | 7 | |
PowerIC | 0:a13d6826cf66 | 8 | #include "mbed.h" |
PowerIC | 0:a13d6826cf66 | 9 | #include "USBHID.h" |
PowerIC | 0:a13d6826cf66 | 10 | #include "max32625pico.h" |
PowerIC | 0:a13d6826cf66 | 11 | #include "i2c.h" |
PowerIC | 0:a13d6826cf66 | 12 | |
PowerIC | 0:a13d6826cf66 | 13 | // configure VDDIOH to local 3.3V supply, set dipVio and swdVio to 1.8V supply |
PowerIC | 0:a13d6826cf66 | 14 | MAX32625PICO pico(MAX32625PICO::IOH_3V3, MAX32625PICO::VIO_1V8, MAX32625PICO::VIO_1V8); |
PowerIC | 0:a13d6826cf66 | 15 | |
PowerIC | 0:a13d6826cf66 | 16 | // We declare a USBHID device. |
PowerIC | 0:a13d6826cf66 | 17 | // HID In/Out Reports are 64 Bytes long |
PowerIC | 0:a13d6826cf66 | 18 | // Vendor ID (VID): 0x0B6A // Maxim Integrated |
PowerIC | 0:a13d6826cf66 | 19 | // Product ID (PID): 0x0001 // |
PowerIC | 0:a13d6826cf66 | 20 | // Serial Number: 0x0001 // |
PowerIC | 0:a13d6826cf66 | 21 | USBHID hid(64, 64, 0x0B6A, 0x0003, 0x0001, true); |
PowerIC | 0:a13d6826cf66 | 22 | |
PowerIC | 0:a13d6826cf66 | 23 | InterruptIn alertb1(P3_2); // Interrupt PIN (INPUT) |
PowerIC | 0:a13d6826cf66 | 24 | InterruptIn alertb2(P3_3); // Interrupt PIN (INPUT) |
PowerIC | 0:a13d6826cf66 | 25 | |
PowerIC | 0:a13d6826cf66 | 26 | DigitalOut red_led(LED1); |
PowerIC | 0:a13d6826cf66 | 27 | DigitalOut green_led(LED2); |
PowerIC | 0:a13d6826cf66 | 28 | DigitalOut blue_led(LED3); |
PowerIC | 0:a13d6826cf66 | 29 | |
PowerIC | 0:a13d6826cf66 | 30 | Timeout to_alertb1; // ALERTB1 timeout |
PowerIC | 0:a13d6826cf66 | 31 | Timeout to_alertb2; // ALERTB2 timeout |
PowerIC | 0:a13d6826cf66 | 32 | |
PowerIC | 0:a13d6826cf66 | 33 | HID_REPORT send_report; |
PowerIC | 0:a13d6826cf66 | 34 | HID_REPORT recv_report; |
PowerIC | 0:a13d6826cf66 | 35 | |
PowerIC | 0:a13d6826cf66 | 36 | //----------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 37 | // USB COMMANDS |
PowerIC | 0:a13d6826cf66 | 38 | //----------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 39 | // LED Command |
PowerIC | 0:a13d6826cf66 | 40 | #define WRITE_LED 0x20 // Send data to the RGB LED |
PowerIC | 0:a13d6826cf66 | 41 | |
PowerIC | 0:a13d6826cf66 | 42 | // I2C1 Commands |
PowerIC | 0:a13d6826cf66 | 43 | #define QUICK_WRITE_I2C1 0x30 // Send Device Address on I2C Master 1, look for ACK |
PowerIC | 0:a13d6826cf66 | 44 | #define READ_BYTE_I2C1 0x31 // Read Data Byte (8-bits) from Register of I2C Device |
PowerIC | 0:a13d6826cf66 | 45 | #define WRITE_BYTE_I2C1 0x32 // Write Data Byte (8-bits) to Register of I2C Device |
PowerIC | 0:a13d6826cf66 | 46 | #define READ_WORD_I2C1 0x33 // Read Data Word (16-bits) from Register of I2C Device |
PowerIC | 0:a13d6826cf66 | 47 | #define WRITE_WORD_I2C1 0x34 // Write Data Word (16-bits) to Register of I2C Device |
PowerIC | 0:a13d6826cf66 | 48 | #define WRITE_BLOCK_I2C1 0x3A // Write Data Block to Register of I2C Device |
PowerIC | 0:a13d6826cf66 | 49 | #define SET_I2C_ADDR 0x3E // Set I2C Slave Address |
PowerIC | 0:a13d6826cf66 | 50 | #define GET_I2C_ADDR 0x3F // Get I2C Slave Address |
PowerIC | 0:a13d6826cf66 | 51 | |
PowerIC | 0:a13d6826cf66 | 52 | // I2C2 Commands |
PowerIC | 0:a13d6826cf66 | 53 | //#define QUICK_WRITE_I2C2 0x35 // Send Device Address on I2C Master 2, look for ACK |
PowerIC | 0:a13d6826cf66 | 54 | //#define READ_BYTE_I2C2 0x36 // Read Data Byte (8-bits) from Register of I2C Device |
PowerIC | 0:a13d6826cf66 | 55 | //#define WRITE_BYTE_I2C2 0x37 // Write Data Byte (8-bits) to Register of I2C Device |
PowerIC | 0:a13d6826cf66 | 56 | //#define READ_WORD_I2C2 0x38 // Read Data Word (16-bits) from Register of I2C Device |
PowerIC | 0:a13d6826cf66 | 57 | //#define WRITE_WORD_I2C2 0x39 // Write Data Word (16-bits) to Register of I2C Device |
PowerIC | 0:a13d6826cf66 | 58 | //#define WRITE_BLOCK_I2C2 0x3B // Write Data Block to Register of I2C Device |
PowerIC | 0:a13d6826cf66 | 59 | |
PowerIC | 0:a13d6826cf66 | 60 | // AE11 Commands |
PowerIC | 0:a13d6826cf66 | 61 | #define GET_FUNC_REGS 0x40 // Return |
PowerIC | 0:a13d6826cf66 | 62 | #define GET_VENDOR_REGS 0x41 // Return |
PowerIC | 0:a13d6826cf66 | 63 | #define GET_INT_REGS 0x42 // Return |
PowerIC | 0:a13d6826cf66 | 64 | #define GET_MASK_REGS 0x43 // Return |
PowerIC | 0:a13d6826cf66 | 65 | #define GET_CTRL_REGS 0x44 // Return |
PowerIC | 0:a13d6826cf66 | 66 | #define GET_TAB1_REGS 0x45 // Return |
PowerIC | 0:a13d6826cf66 | 67 | #define GET_OTP_DATA_REGS 0x46 // Return |
PowerIC | 0:a13d6826cf66 | 68 | #define GET_OTP_TEST_CMD_REGS 0x47 // Return |
PowerIC | 0:a13d6826cf66 | 69 | #define GET_OTP_TEST_MODE_REGS 0x48 // Return |
PowerIC | 0:a13d6826cf66 | 70 | #define GET_OTP_TEST_OVRD_REGS 0x49 // Return |
PowerIC | 0:a13d6826cf66 | 71 | #define OTP_REGS_UNLOCK 0x4A // Return |
PowerIC | 0:a13d6826cf66 | 72 | #define OTP_REGS_LOCK 0x4B // Return |
PowerIC | 0:a13d6826cf66 | 73 | |
PowerIC | 0:a13d6826cf66 | 74 | // INTERRUPT Commands |
PowerIC | 0:a13d6826cf66 | 75 | #define ALERTB1_ASSERTED 0xF0 // ALERTB1 Interrupt |
PowerIC | 0:a13d6826cf66 | 76 | #define CLEAR_INTS 0xF2 // Clear All Interrupts |
PowerIC | 0:a13d6826cf66 | 77 | |
PowerIC | 0:a13d6826cf66 | 78 | // LED CONSTANTS |
PowerIC | 0:a13d6826cf66 | 79 | #define LEDS_OFF 0x00 |
PowerIC | 0:a13d6826cf66 | 80 | #define RED 0x01 |
PowerIC | 0:a13d6826cf66 | 81 | #define GREEN 0x02 |
PowerIC | 0:a13d6826cf66 | 82 | #define BLUE 0x03 |
PowerIC | 0:a13d6826cf66 | 83 | #define YELLOW 0x04 |
PowerIC | 0:a13d6826cf66 | 84 | |
PowerIC | 0:a13d6826cf66 | 85 | // LOGICAL CONSTANTS |
PowerIC | 0:a13d6826cf66 | 86 | #define OFF 0x00 |
PowerIC | 0:a13d6826cf66 | 87 | #define ON 0x01 |
PowerIC | 0:a13d6826cf66 | 88 | |
PowerIC | 0:a13d6826cf66 | 89 | char FUNC_REGS[63] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, |
PowerIC | 0:a13d6826cf66 | 90 | 0x0A, 0x0B, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
PowerIC | 0:a13d6826cf66 | 91 | 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, |
PowerIC | 0:a13d6826cf66 | 92 | 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2E, 0x2F, |
PowerIC | 0:a13d6826cf66 | 93 | 0x30, 0x50, 0x51, 0x70, 0x71, 0x74, 0x75, 0x76, 0x77, 0x78, |
PowerIC | 0:a13d6826cf66 | 94 | 0x79, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, |
PowerIC | 0:a13d6826cf66 | 95 | 0x89, 0x8A, 0x8B }; |
PowerIC | 0:a13d6826cf66 | 96 | |
PowerIC | 0:a13d6826cf66 | 97 | char OTP_DATA_REGS[36] = { 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, |
PowerIC | 0:a13d6826cf66 | 98 | 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, |
PowerIC | 0:a13d6826cf66 | 99 | 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, |
PowerIC | 0:a13d6826cf66 | 100 | 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3 }; |
PowerIC | 0:a13d6826cf66 | 101 | |
PowerIC | 0:a13d6826cf66 | 102 | char OTP_TEST_CMD_REGS[16] = { 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, |
PowerIC | 0:a13d6826cf66 | 103 | 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF }; |
PowerIC | 0:a13d6826cf66 | 104 | |
PowerIC | 0:a13d6826cf66 | 105 | char OTP_TEST_MODE_REGS[23] = { 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, |
PowerIC | 0:a13d6826cf66 | 106 | 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 0xE0, 0xE1, 0xE2, 0xE3, |
PowerIC | 0:a13d6826cf66 | 107 | 0xE4, 0xE5, 0xE6 }; |
PowerIC | 0:a13d6826cf66 | 108 | |
PowerIC | 0:a13d6826cf66 | 109 | char OTP_TEST_OVRD_REGS[13] = { 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, |
PowerIC | 0:a13d6826cf66 | 110 | 0xFA, 0xFB, 0xFC }; |
PowerIC | 0:a13d6826cf66 | 111 | |
PowerIC | 0:a13d6826cf66 | 112 | char VENDOR_REGS[12] = { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, |
PowerIC | 0:a13d6826cf66 | 113 | 0x8A, 0x8B }; |
PowerIC | 0:a13d6826cf66 | 114 | |
PowerIC | 0:a13d6826cf66 | 115 | char INT_REGS[8] = { 0x10, 0x11, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x8B }; |
PowerIC | 0:a13d6826cf66 | 116 | |
PowerIC | 0:a13d6826cf66 | 117 | char MASK_REGS[5] = { 0x12, 0x13, 0x14, 0x15, 0x16 }; |
PowerIC | 0:a13d6826cf66 | 118 | |
PowerIC | 0:a13d6826cf66 | 119 | char CTRL_REGS[5] = { 0x18, 0x19, 0x1A, 0x1B, 0x1C }; |
PowerIC | 0:a13d6826cf66 | 120 | |
PowerIC | 0:a13d6826cf66 | 121 | char TAB1_REGS[29] = { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, |
PowerIC | 0:a13d6826cf66 | 122 | 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x80, 0x81, 0x82, |
PowerIC | 0:a13d6826cf66 | 123 | 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B }; |
PowerIC | 0:a13d6826cf66 | 124 | |
PowerIC | 0:a13d6826cf66 | 125 | //----------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 126 | // VARIABLES |
PowerIC | 0:a13d6826cf66 | 127 | //----------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 128 | char I2C1_RXDATA[40]; |
PowerIC | 0:a13d6826cf66 | 129 | //char I2C2_RXDATA[40]; |
PowerIC | 0:a13d6826cf66 | 130 | char I2C1_TXDATA[40]; |
PowerIC | 0:a13d6826cf66 | 131 | //char I2C2_TXDATA[40]; |
PowerIC | 0:a13d6826cf66 | 132 | static char ALERTB1_STATE = 0x00; // ALERTB1 PIN STATE |
PowerIC | 0:a13d6826cf66 | 133 | static bool ALERTB1_CHANGED = false; |
PowerIC | 0:a13d6826cf66 | 134 | static char I2C_ADDR = 0x00; |
PowerIC | 0:a13d6826cf66 | 135 | |
PowerIC | 0:a13d6826cf66 | 136 | |
PowerIC | 0:a13d6826cf66 | 137 | //----------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 138 | // ALERTB1 INTERRUPT SERVICE ROUTINE |
PowerIC | 0:a13d6826cf66 | 139 | //----------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 140 | void test_alertb1_low() |
PowerIC | 0:a13d6826cf66 | 141 | { |
PowerIC | 0:a13d6826cf66 | 142 | if(alertb1.read() == 0) |
PowerIC | 0:a13d6826cf66 | 143 | { |
PowerIC | 0:a13d6826cf66 | 144 | ALERTB1_STATE = 0x01; // Capture the state of the ALERTB1 pin |
PowerIC | 0:a13d6826cf66 | 145 | ALERTB1_CHANGED = true; |
PowerIC | 0:a13d6826cf66 | 146 | } |
PowerIC | 0:a13d6826cf66 | 147 | } |
PowerIC | 0:a13d6826cf66 | 148 | |
PowerIC | 0:a13d6826cf66 | 149 | void test_alertb1_high() |
PowerIC | 0:a13d6826cf66 | 150 | { |
PowerIC | 0:a13d6826cf66 | 151 | if(alertb1.read() == 1) |
PowerIC | 0:a13d6826cf66 | 152 | { |
PowerIC | 0:a13d6826cf66 | 153 | ALERTB1_STATE = 0x00; // Capture the state of the ALERTB1 pin |
PowerIC | 0:a13d6826cf66 | 154 | ALERTB1_CHANGED = true; |
PowerIC | 0:a13d6826cf66 | 155 | } |
PowerIC | 0:a13d6826cf66 | 156 | } |
PowerIC | 0:a13d6826cf66 | 157 | |
PowerIC | 0:a13d6826cf66 | 158 | void ALERTB1_FALL_ISR() |
PowerIC | 0:a13d6826cf66 | 159 | { |
PowerIC | 0:a13d6826cf66 | 160 | to_alertb1.attach(test_alertb1_low, 0.1); |
PowerIC | 0:a13d6826cf66 | 161 | } |
PowerIC | 0:a13d6826cf66 | 162 | |
PowerIC | 0:a13d6826cf66 | 163 | void ALERTB1_RISE_ISR() |
PowerIC | 0:a13d6826cf66 | 164 | { |
PowerIC | 0:a13d6826cf66 | 165 | to_alertb1.attach(test_alertb1_high, 0.1); |
PowerIC | 0:a13d6826cf66 | 166 | } |
PowerIC | 0:a13d6826cf66 | 167 | |
PowerIC | 0:a13d6826cf66 | 168 | void StartUp_LEDs() |
PowerIC | 0:a13d6826cf66 | 169 | { |
PowerIC | 0:a13d6826cf66 | 170 | red_led = 0; // Turn ON RED LED |
PowerIC | 0:a13d6826cf66 | 171 | wait(0.3); |
PowerIC | 0:a13d6826cf66 | 172 | red_led = 1; // Turn OFF RED LED |
PowerIC | 0:a13d6826cf66 | 173 | green_led = 0; // Turn ON GREEN LED |
PowerIC | 0:a13d6826cf66 | 174 | wait(0.3); |
PowerIC | 0:a13d6826cf66 | 175 | green_led = 1; // Turn OFF GREEN LED |
PowerIC | 0:a13d6826cf66 | 176 | blue_led = 0; // Turn ON BLUE LED |
PowerIC | 0:a13d6826cf66 | 177 | wait(0.3); |
PowerIC | 0:a13d6826cf66 | 178 | blue_led = 1; // Turn OFF BLUE LED |
PowerIC | 0:a13d6826cf66 | 179 | } |
PowerIC | 0:a13d6826cf66 | 180 | |
PowerIC | 0:a13d6826cf66 | 181 | |
PowerIC | 0:a13d6826cf66 | 182 | // main() runs in its own thread in the OS |
PowerIC | 0:a13d6826cf66 | 183 | int main() |
PowerIC | 0:a13d6826cf66 | 184 | { |
PowerIC | 0:a13d6826cf66 | 185 | send_report.length = 64; |
PowerIC | 0:a13d6826cf66 | 186 | recv_report.length = 64; |
PowerIC | 0:a13d6826cf66 | 187 | |
PowerIC | 0:a13d6826cf66 | 188 | StartUp_LEDs(); // Cycle LEDs to show startup |
PowerIC | 0:a13d6826cf66 | 189 | |
PowerIC | 0:a13d6826cf66 | 190 | Init_I2C(); // Make sure we can talk |
PowerIC | 0:a13d6826cf66 | 191 | |
PowerIC | 0:a13d6826cf66 | 192 | alertb1.fall(&ALERTB1_FALL_ISR); // Attaches ALERTB1 to the ISR |
PowerIC | 0:a13d6826cf66 | 193 | alertb1.rise(&ALERTB1_RISE_ISR); |
PowerIC | 0:a13d6826cf66 | 194 | |
PowerIC | 0:a13d6826cf66 | 195 | while (true) |
PowerIC | 0:a13d6826cf66 | 196 | { |
PowerIC | 0:a13d6826cf66 | 197 | if(ALERTB1_CHANGED) |
PowerIC | 0:a13d6826cf66 | 198 | { |
PowerIC | 0:a13d6826cf66 | 199 | send_report.data[0] = ALERTB1_ASSERTED; // Echo Command |
PowerIC | 0:a13d6826cf66 | 200 | send_report.data[1] = ALERTB1_STATE; // Echo INTB State |
PowerIC | 0:a13d6826cf66 | 201 | |
PowerIC | 0:a13d6826cf66 | 202 | for(int i=0;i<8;i++) |
PowerIC | 0:a13d6826cf66 | 203 | { |
PowerIC | 0:a13d6826cf66 | 204 | send_report.data[2 + i] = I2C_Read_Byte(0x00, I2C_ADDR, INT_REGS[i]); // Slave Address must be set! |
PowerIC | 0:a13d6826cf66 | 205 | } |
PowerIC | 0:a13d6826cf66 | 206 | |
PowerIC | 0:a13d6826cf66 | 207 | ALERTB1_CHANGED = false; // Clear the INTB State Changed Flag |
PowerIC | 0:a13d6826cf66 | 208 | hid.sendNB(&send_report); // Send the report (Non-blocking) |
PowerIC | 0:a13d6826cf66 | 209 | } |
PowerIC | 0:a13d6826cf66 | 210 | |
PowerIC | 0:a13d6826cf66 | 211 | if(hid.readNB(&recv_report)) |
PowerIC | 0:a13d6826cf66 | 212 | { |
PowerIC | 0:a13d6826cf66 | 213 | switch(recv_report.data[0]) |
PowerIC | 0:a13d6826cf66 | 214 | { |
PowerIC | 0:a13d6826cf66 | 215 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 216 | case WRITE_LED: // COMMAND [0x20] - WRITE TO RGB LED |
PowerIC | 0:a13d6826cf66 | 217 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 218 | switch(recv_report.data[1]) |
PowerIC | 0:a13d6826cf66 | 219 | { |
PowerIC | 0:a13d6826cf66 | 220 | case LEDS_OFF: |
PowerIC | 0:a13d6826cf66 | 221 | red_led = 1; // Turn OFF RED LED |
PowerIC | 0:a13d6826cf66 | 222 | green_led = 1; // Turn OFF GREEN LED |
PowerIC | 0:a13d6826cf66 | 223 | blue_led = 1; // Turn OFF BLUE LED |
PowerIC | 0:a13d6826cf66 | 224 | break; |
PowerIC | 0:a13d6826cf66 | 225 | case RED: |
PowerIC | 0:a13d6826cf66 | 226 | if(recv_report.data[2] == 1){red_led = 0;} else {red_led = 1;} |
PowerIC | 0:a13d6826cf66 | 227 | break; |
PowerIC | 0:a13d6826cf66 | 228 | case GREEN: |
PowerIC | 0:a13d6826cf66 | 229 | if(recv_report.data[2] == 1){green_led = 0;} else {green_led = 1;} |
PowerIC | 0:a13d6826cf66 | 230 | break; |
PowerIC | 0:a13d6826cf66 | 231 | case BLUE: |
PowerIC | 0:a13d6826cf66 | 232 | if(recv_report.data[2] == 1){blue_led = 0;} else {blue_led = 1;} |
PowerIC | 0:a13d6826cf66 | 233 | break; |
PowerIC | 0:a13d6826cf66 | 234 | default: |
PowerIC | 0:a13d6826cf66 | 235 | break; |
PowerIC | 0:a13d6826cf66 | 236 | }// End Switch (RD1) |
PowerIC | 0:a13d6826cf66 | 237 | |
PowerIC | 0:a13d6826cf66 | 238 | send_report.data[0] = recv_report.data[0]; // Echo Command |
PowerIC | 0:a13d6826cf66 | 239 | send_report.data[1] = recv_report.data[1]; // Echo Subcommand 1 |
PowerIC | 0:a13d6826cf66 | 240 | send_report.data[2] = recv_report.data[2]; // Echo Subcommand 2 |
PowerIC | 0:a13d6826cf66 | 241 | break; |
PowerIC | 0:a13d6826cf66 | 242 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 243 | case QUICK_WRITE_I2C1: // COMMAND [0x30] - QUICK WRITE TO I2C1 |
PowerIC | 0:a13d6826cf66 | 244 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 245 | send_report.data[0] = QUICK_WRITE_I2C1; // Echo Command |
PowerIC | 0:a13d6826cf66 | 246 | send_report.data[1] = recv_report.data[1]; // Echo Subcommand |
PowerIC | 0:a13d6826cf66 | 247 | send_report.data[2] = I2C_Quick_Write(0x00, recv_report.data[1]); // Echo ACK/NACK Status |
PowerIC | 0:a13d6826cf66 | 248 | break; |
PowerIC | 0:a13d6826cf66 | 249 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 250 | case READ_BYTE_I2C1: // COMMAND [0x31] - BYTE READ FROM I2C1 |
PowerIC | 0:a13d6826cf66 | 251 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 252 | send_report.data[0] = READ_BYTE_I2C1; // Echo Command |
PowerIC | 0:a13d6826cf66 | 253 | send_report.data[1] = recv_report.data[1]; // Echo Device Address |
PowerIC | 0:a13d6826cf66 | 254 | send_report.data[2] = recv_report.data[2]; // Echo Register |
PowerIC | 0:a13d6826cf66 | 255 | send_report.data[3] = I2C_Read_Byte(0x00, recv_report.data[1], recv_report.data[2]); // Return Data |
PowerIC | 0:a13d6826cf66 | 256 | break; |
PowerIC | 0:a13d6826cf66 | 257 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 258 | case WRITE_BYTE_I2C1: // COMMAND [0x32] - BYTE WRITE TO I2C1 |
PowerIC | 0:a13d6826cf66 | 259 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 260 | send_report.data[0] = WRITE_BYTE_I2C1; // Echo Command |
PowerIC | 0:a13d6826cf66 | 261 | send_report.data[1] = recv_report.data[1]; // Echo Device Address |
PowerIC | 0:a13d6826cf66 | 262 | send_report.data[2] = recv_report.data[2]; // Echo Register |
PowerIC | 0:a13d6826cf66 | 263 | send_report.data[3] = recv_report.data[3]; // Echo Data |
PowerIC | 0:a13d6826cf66 | 264 | send_report.data[4] = I2C_Write_Register(0x00, recv_report.data[1], recv_report.data[2], recv_report.data[3]); |
PowerIC | 0:a13d6826cf66 | 265 | break; |
PowerIC | 0:a13d6826cf66 | 266 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 267 | case READ_WORD_I2C1: // COMMAND [0x33] - READ WORD FROM I2C1 |
PowerIC | 0:a13d6826cf66 | 268 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 269 | send_report.data[0] = READ_WORD_I2C1; // Echo Command |
PowerIC | 0:a13d6826cf66 | 270 | send_report.data[1] = recv_report.data[1]; // Echo Device Address |
PowerIC | 0:a13d6826cf66 | 271 | send_report.data[2] = recv_report.data[2]; // Echo Register |
PowerIC | 0:a13d6826cf66 | 272 | |
PowerIC | 0:a13d6826cf66 | 273 | unsigned short RX1 = I2C_Read_Word(0x00, recv_report.data[1], recv_report.data[2]); // Read Device |
PowerIC | 0:a13d6826cf66 | 274 | |
PowerIC | 0:a13d6826cf66 | 275 | send_report.data[3] = (char)((RX1 & 0xFF00) >> 8); // Return Data High Byte |
PowerIC | 0:a13d6826cf66 | 276 | send_report.data[4] = (char)(RX1 & 0x00FF); // Return Data Low Byte |
PowerIC | 0:a13d6826cf66 | 277 | break; |
PowerIC | 0:a13d6826cf66 | 278 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 279 | case WRITE_WORD_I2C1: // COMMAND [0x34] - WORD WRITE TO I2C1 |
PowerIC | 0:a13d6826cf66 | 280 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 281 | send_report.data[0] = WRITE_WORD_I2C1; // Echo Command |
PowerIC | 0:a13d6826cf66 | 282 | send_report.data[1] = recv_report.data[1]; // Echo Device Address |
PowerIC | 0:a13d6826cf66 | 283 | send_report.data[2] = recv_report.data[2]; // Echo Register |
PowerIC | 0:a13d6826cf66 | 284 | send_report.data[3] = recv_report.data[3]; // Echo HBData |
PowerIC | 0:a13d6826cf66 | 285 | send_report.data[4] = recv_report.data[4]; // Echo LBData |
PowerIC | 0:a13d6826cf66 | 286 | send_report.data[5] = I2C_Write_Word(0x00, recv_report.data[1], recv_report.data[2], recv_report.data[3], recv_report.data[4]); |
PowerIC | 0:a13d6826cf66 | 287 | break; |
PowerIC | 0:a13d6826cf66 | 288 | |
PowerIC | 0:a13d6826cf66 | 289 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 290 | case WRITE_BLOCK_I2C1: // COMMAND [0x3A] - WRITE A BLOCK of DATA (1 to 10 bytes) TO I2C1 |
PowerIC | 0:a13d6826cf66 | 291 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 292 | send_report.data[0] = WRITE_BLOCK_I2C1; // Echo Command |
PowerIC | 0:a13d6826cf66 | 293 | send_report.data[1] = recv_report.data[1]; // Echo Device Address |
PowerIC | 0:a13d6826cf66 | 294 | send_report.data[2] = recv_report.data[2]; // Echo Register |
PowerIC | 0:a13d6826cf66 | 295 | send_report.data[3] = recv_report.data[3]; // Echo Number of Data Bytes |
PowerIC | 0:a13d6826cf66 | 296 | |
PowerIC | 0:a13d6826cf66 | 297 | I2C1_TXDATA[0] = recv_report.data[2]; // Register Address |
PowerIC | 0:a13d6826cf66 | 298 | |
PowerIC | 0:a13d6826cf66 | 299 | for(int n = 0; n < recv_report.data[3]; n++) |
PowerIC | 0:a13d6826cf66 | 300 | { |
PowerIC | 0:a13d6826cf66 | 301 | I2C1_TXDATA[1 + n] = recv_report.data[4 + n]; // Load TX Buffer with Data |
PowerIC | 0:a13d6826cf66 | 302 | } |
PowerIC | 0:a13d6826cf66 | 303 | |
PowerIC | 0:a13d6826cf66 | 304 | I2C_Write_Block(0x00, recv_report.data[1], recv_report.data[3]); |
PowerIC | 0:a13d6826cf66 | 305 | |
PowerIC | 0:a13d6826cf66 | 306 | break; |
PowerIC | 0:a13d6826cf66 | 307 | |
PowerIC | 0:a13d6826cf66 | 308 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 309 | case SET_I2C_ADDR: // COMMAND [0x3E] - ASSIGN I2C DEVICE ADDRESS FOR SLAVE OPERATIONS |
PowerIC | 0:a13d6826cf66 | 310 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 311 | send_report.data[0] = SET_I2C_ADDR; // Echo Command |
PowerIC | 0:a13d6826cf66 | 312 | I2C_ADDR = recv_report.data[1]; // Assign Slave Address |
PowerIC | 0:a13d6826cf66 | 313 | send_report.data[1] = recv_report.data[1]; // Echo Subcommand |
PowerIC | 0:a13d6826cf66 | 314 | break; |
PowerIC | 0:a13d6826cf66 | 315 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 316 | case GET_I2C_ADDR: // COMMAND [0x3F] - ASSIGN I2C DEVICE ADDRESS FOR SLAVE OPERATIONS |
PowerIC | 0:a13d6826cf66 | 317 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 318 | send_report.data[0] = GET_I2C_ADDR; // Echo Command |
PowerIC | 0:a13d6826cf66 | 319 | send_report.data[1] = I2C_ADDR; // Return Slave Address |
PowerIC | 0:a13d6826cf66 | 320 | break; |
PowerIC | 0:a13d6826cf66 | 321 | /* |
PowerIC | 0:a13d6826cf66 | 322 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 323 | case QUICK_WRITE_I2C2: // COMMAND [0x35] - QUICK WRITE TO I2C2 |
PowerIC | 0:a13d6826cf66 | 324 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 325 | send_report.data[0] = QUICK_WRITE_I2C2; // Echo Command |
PowerIC | 0:a13d6826cf66 | 326 | send_report.data[1] = recv_report.data[1]; // Echo Subcommand |
PowerIC | 0:a13d6826cf66 | 327 | send_report.data[2] = I2C_Quick_Write(0x01, recv_report.data[1]); // Echo ACK/NACK Status |
PowerIC | 0:a13d6826cf66 | 328 | break; |
PowerIC | 0:a13d6826cf66 | 329 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 330 | case READ_BYTE_I2C2: // COMMAND [0x36] - BYTE READ FROM I2C1 |
PowerIC | 0:a13d6826cf66 | 331 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 332 | send_report.data[0] = READ_BYTE_I2C2; // Echo Command |
PowerIC | 0:a13d6826cf66 | 333 | send_report.data[1] = recv_report.data[1]; // Echo Device Address |
PowerIC | 0:a13d6826cf66 | 334 | send_report.data[2] = recv_report.data[2]; // Echo Register |
PowerIC | 0:a13d6826cf66 | 335 | send_report.data[3] = I2C_Read_Byte(0x01, recv_report.data[1], recv_report.data[2]); // Return Data |
PowerIC | 0:a13d6826cf66 | 336 | break; |
PowerIC | 0:a13d6826cf66 | 337 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 338 | case WRITE_BYTE_I2C2: // COMMAND [0x37] - BYTE WRITE TO I2C2 |
PowerIC | 0:a13d6826cf66 | 339 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 340 | send_report.data[0] = WRITE_BYTE_I2C2; // Echo Command |
PowerIC | 0:a13d6826cf66 | 341 | send_report.data[1] = recv_report.data[1]; // Echo Device Address |
PowerIC | 0:a13d6826cf66 | 342 | send_report.data[2] = recv_report.data[2]; // Echo Register |
PowerIC | 0:a13d6826cf66 | 343 | send_report.data[3] = recv_report.data[3]; // Echo Data |
PowerIC | 0:a13d6826cf66 | 344 | send_report.data[4] = I2C_Write_Register(0x01, recv_report.data[1], recv_report.data[2], recv_report.data[3]); |
PowerIC | 0:a13d6826cf66 | 345 | break; |
PowerIC | 0:a13d6826cf66 | 346 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 347 | case READ_WORD_I2C2: // COMMAND [0x38] - READ WORD FROM I2C2 |
PowerIC | 0:a13d6826cf66 | 348 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 349 | send_report.data[0] = READ_WORD_I2C2; // Echo Command |
PowerIC | 0:a13d6826cf66 | 350 | send_report.data[1] = recv_report.data[1]; // Echo Device Address |
PowerIC | 0:a13d6826cf66 | 351 | send_report.data[2] = recv_report.data[2]; // Echo Register |
PowerIC | 0:a13d6826cf66 | 352 | |
PowerIC | 0:a13d6826cf66 | 353 | unsigned short RX2 = I2C_Read_Word(0x01, recv_report.data[1], recv_report.data[2]); // Read Device |
PowerIC | 0:a13d6826cf66 | 354 | |
PowerIC | 0:a13d6826cf66 | 355 | send_report.data[3] = (char)((RX2 & 0xFF00) >> 8); // Return Data High Byte |
PowerIC | 0:a13d6826cf66 | 356 | send_report.data[4] = (char)(RX2 & 0x00FF); // Return Data Low Byte |
PowerIC | 0:a13d6826cf66 | 357 | break; |
PowerIC | 0:a13d6826cf66 | 358 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 359 | case WRITE_WORD_I2C2: // COMMAND [0x39] - WORD WRITE TO I2C2 |
PowerIC | 0:a13d6826cf66 | 360 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 361 | send_report.data[0] = WRITE_WORD_I2C2; // Echo Command |
PowerIC | 0:a13d6826cf66 | 362 | send_report.data[1] = recv_report.data[1]; // Echo Device Address |
PowerIC | 0:a13d6826cf66 | 363 | send_report.data[2] = recv_report.data[2]; // Echo Register |
PowerIC | 0:a13d6826cf66 | 364 | send_report.data[3] = recv_report.data[3]; // Echo HBData |
PowerIC | 0:a13d6826cf66 | 365 | send_report.data[4] = recv_report.data[4]; // Echo LBData |
PowerIC | 0:a13d6826cf66 | 366 | send_report.data[5] = I2C_Write_Word(0x01, recv_report.data[1], recv_report.data[2], recv_report.data[3], recv_report.data[4]); |
PowerIC | 0:a13d6826cf66 | 367 | break; |
PowerIC | 0:a13d6826cf66 | 368 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 369 | case WRITE_BLOCK_I2C2: // COMMAND [0x3B] - WRITE A BLOCK of DATA (1 to 10 bytes) TO I2C2 |
PowerIC | 0:a13d6826cf66 | 370 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 371 | send_report.data[0] = WRITE_BLOCK_I2C2; // Echo Command |
PowerIC | 0:a13d6826cf66 | 372 | send_report.data[1] = recv_report.data[1]; // Echo Device Address |
PowerIC | 0:a13d6826cf66 | 373 | send_report.data[2] = recv_report.data[2]; // Echo Register |
PowerIC | 0:a13d6826cf66 | 374 | send_report.data[3] = recv_report.data[3]; // Echo Number of Data Bytes |
PowerIC | 0:a13d6826cf66 | 375 | |
PowerIC | 0:a13d6826cf66 | 376 | I2C2_TXDATA[0] = recv_report.data[2]; // Register Address |
PowerIC | 0:a13d6826cf66 | 377 | |
PowerIC | 0:a13d6826cf66 | 378 | for(int n = 0; n < recv_report.data[3]; n++) |
PowerIC | 0:a13d6826cf66 | 379 | { |
PowerIC | 0:a13d6826cf66 | 380 | I2C2_TXDATA[1 + n] = recv_report.data[4 + n]; // Load TX Buffer with Data |
PowerIC | 0:a13d6826cf66 | 381 | } |
PowerIC | 0:a13d6826cf66 | 382 | |
PowerIC | 0:a13d6826cf66 | 383 | I2C_Write_Block(0x01, recv_report.data[1], recv_report.data[3]); |
PowerIC | 0:a13d6826cf66 | 384 | |
PowerIC | 0:a13d6826cf66 | 385 | break; |
PowerIC | 0:a13d6826cf66 | 386 | */ |
PowerIC | 0:a13d6826cf66 | 387 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 388 | case GET_FUNC_REGS: // COMMAND [0x40] - BLOCK READ OF MAX25430 FUNCTIONAL REGISTERS |
PowerIC | 0:a13d6826cf66 | 389 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 390 | send_report.data[0] = GET_FUNC_REGS; // Echo Command |
PowerIC | 0:a13d6826cf66 | 391 | send_report.data[1] = recv_report.data[1]; // Echo I2C Device Address |
PowerIC | 0:a13d6826cf66 | 392 | |
PowerIC | 0:a13d6826cf66 | 393 | for(int i=0;i<63;i++) |
PowerIC | 0:a13d6826cf66 | 394 | { |
PowerIC | 0:a13d6826cf66 | 395 | send_report.data[2 + i] = I2C_Read_Byte(0x00, recv_report.data[1], FUNC_REGS[i]); |
PowerIC | 0:a13d6826cf66 | 396 | } |
PowerIC | 0:a13d6826cf66 | 397 | |
PowerIC | 0:a13d6826cf66 | 398 | break; |
PowerIC | 0:a13d6826cf66 | 399 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 400 | case GET_VENDOR_REGS: // COMMAND [0x41] - BLOCK READ OF MAX25430 VENDOR REGISTERS |
PowerIC | 0:a13d6826cf66 | 401 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 402 | send_report.data[0] = GET_VENDOR_REGS; // Echo Command |
PowerIC | 0:a13d6826cf66 | 403 | send_report.data[1] = recv_report.data[1]; // Echo I2C Device Address |
PowerIC | 0:a13d6826cf66 | 404 | |
PowerIC | 0:a13d6826cf66 | 405 | for(int i=0;i<12;i++) |
PowerIC | 0:a13d6826cf66 | 406 | { |
PowerIC | 0:a13d6826cf66 | 407 | send_report.data[2 + i] = I2C_Read_Byte(0x00, recv_report.data[1], VENDOR_REGS[i]); |
PowerIC | 0:a13d6826cf66 | 408 | } |
PowerIC | 0:a13d6826cf66 | 409 | |
PowerIC | 0:a13d6826cf66 | 410 | break; |
PowerIC | 0:a13d6826cf66 | 411 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 412 | case GET_INT_REGS: // COMMAND [0x42] - BLOCK READ OF MAX25430 INTERRUPT REGISTERS |
PowerIC | 0:a13d6826cf66 | 413 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 414 | send_report.data[0] = GET_INT_REGS; // Echo Command |
PowerIC | 0:a13d6826cf66 | 415 | send_report.data[1] = recv_report.data[1]; // Echo I2C Device Address |
PowerIC | 0:a13d6826cf66 | 416 | |
PowerIC | 0:a13d6826cf66 | 417 | for(int i=0;i<8;i++) |
PowerIC | 0:a13d6826cf66 | 418 | { |
PowerIC | 0:a13d6826cf66 | 419 | send_report.data[2 + i] = I2C_Read_Byte(0x00, recv_report.data[1], INT_REGS[i]); |
PowerIC | 0:a13d6826cf66 | 420 | } |
PowerIC | 0:a13d6826cf66 | 421 | |
PowerIC | 0:a13d6826cf66 | 422 | break; |
PowerIC | 0:a13d6826cf66 | 423 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 424 | case GET_MASK_REGS: // COMMAND [0x43] - BLOCK READ OF MAX25430 MASK REGISTERS |
PowerIC | 0:a13d6826cf66 | 425 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 426 | send_report.data[0] = GET_MASK_REGS; // Echo Command |
PowerIC | 0:a13d6826cf66 | 427 | send_report.data[1] = recv_report.data[1]; // Echo I2C Device Address |
PowerIC | 0:a13d6826cf66 | 428 | |
PowerIC | 0:a13d6826cf66 | 429 | for(int i=0;i<5;i++) |
PowerIC | 0:a13d6826cf66 | 430 | { |
PowerIC | 0:a13d6826cf66 | 431 | send_report.data[2 + i] = I2C_Read_Byte(0x00, recv_report.data[1], MASK_REGS[i]); |
PowerIC | 0:a13d6826cf66 | 432 | } |
PowerIC | 0:a13d6826cf66 | 433 | |
PowerIC | 0:a13d6826cf66 | 434 | break; |
PowerIC | 0:a13d6826cf66 | 435 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 436 | case GET_CTRL_REGS: // COMMAND [0x44] - BLOCK READ OF MAX25430 TCPC CONTROL REGISTERS |
PowerIC | 0:a13d6826cf66 | 437 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 438 | send_report.data[0] = GET_CTRL_REGS; // Echo Command |
PowerIC | 0:a13d6826cf66 | 439 | send_report.data[1] = recv_report.data[1]; // Echo I2C Device Address |
PowerIC | 0:a13d6826cf66 | 440 | |
PowerIC | 0:a13d6826cf66 | 441 | for(int i=0;i<5;i++) |
PowerIC | 0:a13d6826cf66 | 442 | { |
PowerIC | 0:a13d6826cf66 | 443 | send_report.data[2 + i] = I2C_Read_Byte(0x00, recv_report.data[1], CTRL_REGS[i]); |
PowerIC | 0:a13d6826cf66 | 444 | } |
PowerIC | 0:a13d6826cf66 | 445 | |
PowerIC | 0:a13d6826cf66 | 446 | break; |
PowerIC | 0:a13d6826cf66 | 447 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 448 | case GET_TAB1_REGS: // COMMAND [0x45] - BLOCK READ OF MAX25430 TAB1 REGISTERS |
PowerIC | 0:a13d6826cf66 | 449 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 450 | send_report.data[0] = GET_TAB1_REGS; // Echo Command |
PowerIC | 0:a13d6826cf66 | 451 | send_report.data[1] = recv_report.data[1]; // Echo I2C Device Address |
PowerIC | 0:a13d6826cf66 | 452 | |
PowerIC | 0:a13d6826cf66 | 453 | for(int i=0;i<29;i++) |
PowerIC | 0:a13d6826cf66 | 454 | { |
PowerIC | 0:a13d6826cf66 | 455 | send_report.data[2 + i] = I2C_Read_Byte(0x00, recv_report.data[1], TAB1_REGS[i]); |
PowerIC | 0:a13d6826cf66 | 456 | } |
PowerIC | 0:a13d6826cf66 | 457 | |
PowerIC | 0:a13d6826cf66 | 458 | break; |
PowerIC | 0:a13d6826cf66 | 459 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 460 | case GET_OTP_DATA_REGS: // COMMAND [0x46] - BLOCK READ OF MAX25430 OTP DATA REGISTERS |
PowerIC | 0:a13d6826cf66 | 461 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 462 | send_report.data[0] = GET_OTP_DATA_REGS; // Echo Command |
PowerIC | 0:a13d6826cf66 | 463 | send_report.data[1] = recv_report.data[1]; // Echo I2C Device Address |
PowerIC | 0:a13d6826cf66 | 464 | |
PowerIC | 0:a13d6826cf66 | 465 | for(int i=0;i<36;i++) |
PowerIC | 0:a13d6826cf66 | 466 | { |
PowerIC | 0:a13d6826cf66 | 467 | send_report.data[2 + i] = I2C_Read_Byte(0x00, recv_report.data[1], OTP_DATA_REGS[i]); |
PowerIC | 0:a13d6826cf66 | 468 | } |
PowerIC | 0:a13d6826cf66 | 469 | |
PowerIC | 0:a13d6826cf66 | 470 | break; |
PowerIC | 0:a13d6826cf66 | 471 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 472 | case GET_OTP_TEST_CMD_REGS: // COMMAND [0x47] - BLOCK READ OF MAX25430 OTP TEST COMMAND REGISTERS |
PowerIC | 0:a13d6826cf66 | 473 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 474 | send_report.data[0] = GET_OTP_TEST_CMD_REGS; // Echo Command |
PowerIC | 0:a13d6826cf66 | 475 | send_report.data[1] = recv_report.data[1]; // Echo I2C Device Address |
PowerIC | 0:a13d6826cf66 | 476 | |
PowerIC | 0:a13d6826cf66 | 477 | for(int i=0;i<16;i++) |
PowerIC | 0:a13d6826cf66 | 478 | { |
PowerIC | 0:a13d6826cf66 | 479 | send_report.data[2 + i] = I2C_Read_Byte(0x00, recv_report.data[1], OTP_TEST_CMD_REGS[i]); |
PowerIC | 0:a13d6826cf66 | 480 | } |
PowerIC | 0:a13d6826cf66 | 481 | |
PowerIC | 0:a13d6826cf66 | 482 | break; |
PowerIC | 0:a13d6826cf66 | 483 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 484 | case GET_OTP_TEST_MODE_REGS: // COMMAND [0x48] - BLOCK READ OF MAX25430 OTP TEST MODE REGISTERS |
PowerIC | 0:a13d6826cf66 | 485 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 486 | send_report.data[0] = GET_OTP_TEST_MODE_REGS; // Echo Command |
PowerIC | 0:a13d6826cf66 | 487 | send_report.data[1] = recv_report.data[1]; // Echo I2C Device Address |
PowerIC | 0:a13d6826cf66 | 488 | |
PowerIC | 0:a13d6826cf66 | 489 | for(int i=0;i<23;i++) |
PowerIC | 0:a13d6826cf66 | 490 | { |
PowerIC | 0:a13d6826cf66 | 491 | send_report.data[2 + i] = I2C_Read_Byte(0x00, recv_report.data[1], OTP_TEST_MODE_REGS[i]); |
PowerIC | 0:a13d6826cf66 | 492 | } |
PowerIC | 0:a13d6826cf66 | 493 | |
PowerIC | 0:a13d6826cf66 | 494 | break; |
PowerIC | 0:a13d6826cf66 | 495 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 496 | case GET_OTP_TEST_OVRD_REGS: // COMMAND [0x49] - BLOCK READ OF MAX25430 OTP TEST OVERRIDE REGISTERS |
PowerIC | 0:a13d6826cf66 | 497 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 498 | send_report.data[0] = GET_OTP_TEST_OVRD_REGS; // Echo Command |
PowerIC | 0:a13d6826cf66 | 499 | send_report.data[1] = recv_report.data[1]; // Echo I2C Device Address |
PowerIC | 0:a13d6826cf66 | 500 | |
PowerIC | 0:a13d6826cf66 | 501 | for(int i=0;i<13;i++) |
PowerIC | 0:a13d6826cf66 | 502 | { |
PowerIC | 0:a13d6826cf66 | 503 | send_report.data[2 + i] = I2C_Read_Byte(0x00, recv_report.data[1], OTP_TEST_OVRD_REGS[i]); |
PowerIC | 0:a13d6826cf66 | 504 | } |
PowerIC | 0:a13d6826cf66 | 505 | |
PowerIC | 0:a13d6826cf66 | 506 | break; |
PowerIC | 0:a13d6826cf66 | 507 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 508 | case OTP_REGS_UNLOCK: // COMMAND [0x4A] - UNLOCK MAX25430 OTP REGISTERS |
PowerIC | 0:a13d6826cf66 | 509 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 510 | send_report.data[0] = OTP_REGS_UNLOCK; // Echo Command |
PowerIC | 0:a13d6826cf66 | 511 | send_report.data[1] = recv_report.data[1]; // Echo I2C Device Address |
PowerIC | 0:a13d6826cf66 | 512 | |
PowerIC | 0:a13d6826cf66 | 513 | I2C_Write_Register(0x00, recv_report.data[1], 0xC0, 0x12); |
PowerIC | 0:a13d6826cf66 | 514 | I2C_Write_Register(0x00, recv_report.data[1], 0xC0, 0x34); |
PowerIC | 0:a13d6826cf66 | 515 | I2C_Write_Register(0x00, recv_report.data[1], 0xC0, 0xFA); |
PowerIC | 0:a13d6826cf66 | 516 | I2C_Write_Register(0x00, recv_report.data[1], 0xC0, 0xDB); |
PowerIC | 0:a13d6826cf66 | 517 | |
PowerIC | 0:a13d6826cf66 | 518 | send_report.data[2] = 0x01; // Task Complete |
PowerIC | 0:a13d6826cf66 | 519 | |
PowerIC | 0:a13d6826cf66 | 520 | break; |
PowerIC | 0:a13d6826cf66 | 521 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 522 | case OTP_REGS_LOCK: // COMMAND [0x4B] - LOCK MAX25430 OTP REGISTERS |
PowerIC | 0:a13d6826cf66 | 523 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 524 | send_report.data[0] = OTP_REGS_LOCK; // Echo Command |
PowerIC | 0:a13d6826cf66 | 525 | send_report.data[1] = recv_report.data[1]; // Echo I2C Device Address |
PowerIC | 0:a13d6826cf66 | 526 | |
PowerIC | 0:a13d6826cf66 | 527 | I2C_Write_Register(0x00, recv_report.data[1], 0xC0, 0x00); |
PowerIC | 0:a13d6826cf66 | 528 | I2C_Write_Register(0x00, recv_report.data[1], 0xC0, 0x00); |
PowerIC | 0:a13d6826cf66 | 529 | I2C_Write_Register(0x00, recv_report.data[1], 0xC0, 0x00); |
PowerIC | 0:a13d6826cf66 | 530 | I2C_Write_Register(0x00, recv_report.data[1], 0xC0, 0x00); |
PowerIC | 0:a13d6826cf66 | 531 | |
PowerIC | 0:a13d6826cf66 | 532 | send_report.data[2] = 0x01; // Task Complete |
PowerIC | 0:a13d6826cf66 | 533 | |
PowerIC | 0:a13d6826cf66 | 534 | break; |
PowerIC | 0:a13d6826cf66 | 535 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 536 | case CLEAR_INTS: // COMMAND [0xF2] - CLEAR ALL MAX25430 INTERRUPT REGISTERS |
PowerIC | 0:a13d6826cf66 | 537 | //----------------------------------------------------------------------------------------------------------------- |
PowerIC | 0:a13d6826cf66 | 538 | send_report.data[0] = CLEAR_INTS; // Echo Command |
PowerIC | 0:a13d6826cf66 | 539 | send_report.data[1] = recv_report.data[1]; // Echo I2C Device Address |
PowerIC | 0:a13d6826cf66 | 540 | |
PowerIC | 0:a13d6826cf66 | 541 | I2C_Write_Register(0x00, recv_report.data[1], 0x10, 0xFF); // ALERT STATUS LB |
PowerIC | 0:a13d6826cf66 | 542 | I2C_Write_Register(0x00, recv_report.data[1], 0x11, 0xA7); // ALERT STATUS HB |
PowerIC | 0:a13d6826cf66 | 543 | I2C_Write_Register(0x00, recv_report.data[1], 0x1F, 0xFF); // FAULT STATUS |
PowerIC | 0:a13d6826cf66 | 544 | |
PowerIC | 0:a13d6826cf66 | 545 | send_report.data[2] = 0x55; // Task Complete |
PowerIC | 0:a13d6826cf66 | 546 | |
PowerIC | 0:a13d6826cf66 | 547 | break; |
PowerIC | 0:a13d6826cf66 | 548 | |
PowerIC | 0:a13d6826cf66 | 549 | default: |
PowerIC | 0:a13d6826cf66 | 550 | break; |
PowerIC | 0:a13d6826cf66 | 551 | }// End Switch - Command Interpretor |
PowerIC | 0:a13d6826cf66 | 552 | |
PowerIC | 0:a13d6826cf66 | 553 | //Send the report |
PowerIC | 0:a13d6826cf66 | 554 | hid.send(&send_report); |
PowerIC | 0:a13d6826cf66 | 555 | }// End If - HID Message |
PowerIC | 0:a13d6826cf66 | 556 | }// End Main While Loop |
PowerIC | 0:a13d6826cf66 | 557 | }// End Main |