You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally posted by Poofjunior May 18, 2023
Hi everyone,
I'd like to propose a minor feature tweak to the existing (and future) harp protocol.
For register reads and writes, I propose that if we read/write more than the specified number of bytes, we simply continue reading/writing sequentially from the next register.
The main benefit is that we can read/write groups of sequential registers. For future harp devices, we can then group related registers together, which enables us to read/write structs.
In C++, this is straightforward to implement if the register data is stored in a packed struct.
// Example register values stored contiguously in memory with a packed struct (i.e no padding).
#pragma pack(push, 1)
structRegValues
{
constint16_t R_POSITION_X;
constint16_t R_POSITION_Y;
constint16_t R_POSITION_Z;
constuint8_t R_RESET_POSITION;
};
#pragma pack(pop)
Suppose we want to read out the x,y, and z position as a single harp read request, instead of 3 register read requests. Then, on the client side, we simply ask for 6 bytes. Since they're stored contiguously in memory with no padding, the embedded device can just memcpy it into the outgoing packet. In fact, if the data on the harp device is already stored contiguously in memory, then little-to-no changes on the embedded device need to be adjusted.
Here's some "client-side" pseudocode.
dev=harp_device("3D_JOYSTICK")
x=dev.read_request(reg=R_POSITION_X, bytes=2).payload.unpack('<l')
y=dev.read_request(reg=R_POSITION_Y, bytes=2).payload.unpack('<l')
z=dev.read_request(reg=R_POSITION_Z, bytes=2).payload.unpack('<l')
# versusposition_xyz=dev.read_request(reg=R_POSITION_X, bytes=6).payload.unpack('<lll') # Returns a payload of 6 bytes, aka: 3-little-endian ints
For reference, this is a common way of interacting with a number of ASICs with a register map on serial interfaces like i2c or SPI. Examples include sensors from Bosch like the BMA180, BNO085, etc.
Overall, I think this small tweak lets you basically send/receive groups of data in of mixed payload sizes that can be then reinterpreted from the client side as a struct. This feature is also backward-compatible with existing systems without necessitating any changes. They can simply ignore this feature.
LMK what y'all think!
The text was updated successfully, but these errors were encountered:
Discussed in #27
Originally posted by Poofjunior May 18, 2023
Hi everyone,
I'd like to propose a minor feature tweak to the existing (and future) harp protocol.
For register reads and writes, I propose that if we read/write more than the specified number of bytes, we simply continue reading/writing sequentially from the next register.
The main benefit is that we can read/write groups of sequential registers. For future harp devices, we can then group related registers together, which enables us to read/write structs.
In C++, this is straightforward to implement if the register data is stored in a packed struct.
Suppose we want to read out the x,y, and z position as a single harp read request, instead of 3 register read requests. Then, on the client side, we simply ask for 6 bytes. Since they're stored contiguously in memory with no padding, the embedded device can just memcpy it into the outgoing packet. In fact, if the data on the harp device is already stored contiguously in memory, then little-to-no changes on the embedded device need to be adjusted.
Here's some "client-side" pseudocode.
For reference, this is a common way of interacting with a number of ASICs with a register map on serial interfaces like i2c or SPI. Examples include sensors from Bosch like the BMA180, BNO085, etc.
Overall, I think this small tweak lets you basically send/receive groups of data in of mixed payload sizes that can be then reinterpreted from the client side as a struct. This feature is also backward-compatible with existing systems without necessitating any changes. They can simply ignore this feature.
LMK what y'all think!
The text was updated successfully, but these errors were encountered: