Fix really stupid bug in reset_buffer_count

This commit is contained in:
Musa Mahmood 2025-04-17 23:07:08 -04:00
parent 919523a465
commit dad3d7d48d
3 changed files with 29 additions and 8 deletions

View File

@ -112,8 +112,8 @@ void ads1298_initialize(ads1298_info_t *p_info) {
NRF_LOG_FLUSH();
#endif
// Prepare packet header to ID as "ADS1298"
p_info->usb_buffer[0] = TN_IC_ADS1298;
// 0xDF = see extended table
p_info->usb_buffer[0] = IC_ID_ADS1298;
}
void ads1298_uninitialize(void) {

4
main.c
View File

@ -74,7 +74,7 @@ APP_USBD_CDC_ACM_GLOBAL_DEF(m_app_cdc_acm,
APP_USBD_CDC_COMM_PROTOCOL_AT_V250);
__STATIC_INLINE void reset_buffer_count(uint8_t *buffer_start) {
buffer_start[0] = 0;
buffer_start[1] = 0;
}
__STATIC_INLINE void increment_packet(uint8_t *buffer_start) {
@ -168,7 +168,7 @@ void read_ic_settings(uint8_t* new_packet) {
// read all registers into m_info.registers
ads1298_readback_registers(&m_info);
// Send back over USB.
usb_send_push_ex(REGISTER_READBACK_PREFIX, REGISTER_READBACK_ADS1298,
usb_send_push_ex(CTRL_REGISTER_READBACK, IC_ID_ADS1298,
m_info.registers, ADS1298_REGISTER_COUNT);
ads1298_start_rdatac();
ads1298_standby();

View File

@ -46,14 +46,35 @@
#define TN_MISC_RTT_REQUEST 0x1
// #################### RESPONSE CODES ####################
// #NOTE: 0x01 and 0x02 are reserved (for now) for legacy BLE reasons. I should deprecate and
// remove these.
#define CTRL_STAT_INFO_STRING 0x01
#define CTRL_STAT_INFO_BYTES_SENT 0x02
#define CTRL_STAT_INFO_PERIPHERALS 0x03
#define CTRL_STAT_INFO_HW_FW_VERSION 0x04
#define CTRL_STAT_INFO_WHO_AM_I 0x05
#define REGISTER_READBACK_PREFIX 0xC8
#define ID_REGISTER_READBACK_PREFIX 0xC9
#define REGISTER_READBACK_ADS1298 TN_IC_ADS1298
#define CTRL_STAT_INFO_BATTERY_LEVEL 0xB1
// For register readback, the following bytes will be ic-dependent, as
// some devices have more than 62 bytes worth of registers, so it may
// need to be split up into pages.
#define CTRL_REGISTER_READBACK 0xC8
#define CTRL_ACK_RTT_REQUEST 0xE0
// %%% IC Identifiers %%%
// I want a SINGLE table for 8-bit IDs corresponding to different ICs
// These values can be anything from 0x06:0xFF, as long as it doesn't conflict
// with any of the reserved ones from above.
// If the USB packet leads [0] with the ID, then it is a data packet
// in the typical format of [ID, Serial, ...data] where the length of data
// should be statically determined in advance.
// For example, with the ADS1298, the packet length is determined based on the
// channel count (see: ads1298_set_data_buffer_length for more details)
// #define RESPONSE_PACKET 0x00
#define IC_ID_ADS1298 0xD1
#define IC_ID_EXT 0xFF // see next byte for extended table
#define FIRST_NIBBLE(x) ((x >> 4) & 0xF)
#define SECOND_NIBBLE(x) (x & 0xF)