|
17 | 17 | #include "controls.h" |
18 | 18 |
|
19 | 19 | #include "DrivebrainInterface.h" |
20 | | -#include "IOExpander.h" |
21 | 20 | #include "IOExpanderUtils.h" |
22 | 21 |
|
23 | 22 | float apply_iir_filter(float alpha, float old_value, float new_value) |
@@ -189,32 +188,49 @@ HT_TASK::TaskResponse handle_send_VCR_ethernet_data(const unsigned long& sysMicr |
189 | 188 |
|
190 | 189 | HT_TASK::TaskResponse init_ioexpander(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo) |
191 | 190 | { |
192 | | - IOExpanderInstance::create(0x20); |
| 191 | + Wire2.begin(); // copied from VCF but why Wire 2? |
| 192 | + IOExpanderInstance::create(0x20, Wire2); |
| 193 | + IOExpanderInstance::instance().init(); |
| 194 | + |
| 195 | + // setting GPB7 as an output (required by datasheet) and the rest as inputs for both ports |
| 196 | + IOExpanderInstance::instance().portMode(MCP23017Port::A, 0b01111111); |
| 197 | + IOExpanderInstance::instance().portMode(MCP23017Port::B, 0b01111111); |
| 198 | + |
| 199 | + // configure internal pull-ups (required by datasheet) |
| 200 | + IOExpanderInstance::instance().writeRegister(MCP23017Register::GPPU_A, 0xFF); |
| 201 | + IOExpanderInstance::instance().writeRegister(MCP23017Register::GPPU_B, 0xFF); |
| 202 | + |
| 203 | + IOExpanderInstance::instance().writeRegister(MCP23017Register::IPOL_B, 0xFF); |
| 204 | + |
193 | 205 | return HT_TASK::TaskResponse::YIELD; |
194 | 206 | } |
195 | 207 |
|
| 208 | + |
| 209 | +// need to double check pin assigments |
196 | 210 | HT_TASK::TaskResponse read_ioexpander(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo) |
197 | 211 | { |
198 | 212 | // NOLINTBEGIN |
199 | 213 |
|
200 | | - // TODO: Make this consistent with VCF implementation (make sure internal pullups are configured) |
201 | | - |
202 | | - uint16_t data = 0; |
203 | | - data = IOExpanderInstance::instance().read(); |
204 | | - vcr_data.interface_data.shutdown_sensing_data.bspd_is_ok = IOExpanderUtils::getBit(data, 0, 0); |
205 | | - vcr_data.interface_data.shutdown_sensing_data.k_watchdog_relay = IOExpanderUtils::getBit(data, 0, 1); |
206 | | - vcr_data.interface_data.shutdown_sensing_data.watchdog_is_ok = IOExpanderUtils::getBit(data, 0, 2); |
207 | | - vcr_data.interface_data.shutdown_sensing_data.l_bms_relay = IOExpanderUtils::getBit(data, 0, 3); |
208 | | - vcr_data.interface_data.shutdown_sensing_data.bms_is_ok = IOExpanderUtils::getBit(data, 0, 4); |
209 | | - vcr_data.interface_data.shutdown_sensing_data.m_imd_relay = IOExpanderUtils::getBit(data, 0, 5); |
210 | | - vcr_data.interface_data.shutdown_sensing_data.imd_is_ok = IOExpanderUtils::getBit(data, 0, 6); |
211 | | - |
212 | | - vcr_data.interface_data.ethernet_is_linked.acu_link = IOExpanderUtils::getBit(data, 1, 0); |
213 | | - vcr_data.interface_data.ethernet_is_linked.drivebrain_link = IOExpanderUtils::getBit(data, 1, 1); |
214 | | - vcr_data.interface_data.ethernet_is_linked.vcf_link = IOExpanderUtils::getBit(data, 1, 2); |
215 | | - vcr_data.interface_data.ethernet_is_linked.teensy_link = IOExpanderUtils::getBit(data, 1, 3); |
216 | | - vcr_data.interface_data.ethernet_is_linked.debug_link = IOExpanderUtils::getBit(data, 1, 4); |
217 | | - vcr_data.interface_data.ethernet_is_linked.ubiquiti_link = IOExpanderUtils::getBit(data, 1, 5); |
| 214 | + uint16_t data = IOExpanderInstance::instance().read(); |
| 215 | + |
| 216 | + Serial.print(IOExpanderUtils::getBit(data, 0, 1)); |
| 217 | + |
| 218 | + // inputs on port a (0) |
| 219 | + vcr_data.interface_data.shutdown_sensing_data.bspd_is_ok = IOExpanderUtils::getBit(data, 0, 1); |
| 220 | + //vcr_data.interface_data.shutdown_sensing_data.bspd_fault = IOExpanderUtils::getBit(data, 0, 2); //need to add bspd fault to shdn sensing data in shared firmware types |
| 221 | + //vcr_data.interface_data.ethernet_is_linked.vn_link = IOExpanderUtils::getBit(data, 0, 3); //need to add vn_link to ethernet is linked in shared firmware types |
| 222 | + vcr_data.interface_data.ethernet_is_linked.drivebrain_link = IOExpanderUtils::getBit(data, 0, 4); |
| 223 | + vcr_data.interface_data.ethernet_is_linked.ubiquiti_link = IOExpanderUtils::getBit(data, 0, 5); |
| 224 | + //vcr_data.interface_data.shutdown_sensing_data.bspd_missing = IOExpanderUtils::getBit(data, 0, 6); //need to add to shared firmware types |
| 225 | + |
| 226 | + // inputs on port b (1) |
| 227 | + //vcr_data.interface_data.shutdown_sensing_data.lv_present = IOExpanderUtils::getBit(data, 1, 0); //need to add |
| 228 | + vcr_data.interface_data.shutdown_sensing_data.bms_is_ok = IOExpanderUtils::getBit(data, 1, 1); // i also need to update the shutdown sensing struct |
| 229 | + vcr_data.interface_data.shutdown_sensing_data.imd_is_ok = IOExpanderUtils::getBit(data, 1, 2); |
| 230 | + //vcr_data.interface_data.shutdown_sensing_data.vcr_is_ok = IOExpanderUtils::getBit(data, 1, 3); //need to add |
| 231 | + vcr_data.interface_data.ethernet_is_linked.acu_link = IOExpanderUtils::getBit(data, 1, 4); |
| 232 | + vcr_data.interface_data.ethernet_is_linked.teensy_link = IOExpanderUtils::getBit(data, 1, 5); |
| 233 | + vcr_data.interface_data.ethernet_is_linked.vcf_link = IOExpanderUtils::getBit(data, 1, 6); |
218 | 234 |
|
219 | 235 | return HT_TASK::TaskResponse::YIELD; |
220 | 236 | // NOLINTEND |
|
0 commit comments