|
|
|
|
@ -20,7 +20,8 @@ static TaskHandle_t i2c_comms_task_handle = NULL;
|
|
|
|
|
static SemaphoreHandle_t motor_status_semaphore;
|
|
|
|
|
static xQueueHandle motor_status_queue;
|
|
|
|
|
|
|
|
|
|
motor_status_packet_t i2c_reply;
|
|
|
|
|
static xQueueHandle motor_control_queue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Ask the I2C task to get get a status update from the motor ESP32
|
|
|
|
|
void request_motor_status_update() {
|
|
|
|
|
@ -33,8 +34,14 @@ bool get_motor_status_update(motor_status_packet_t *status_packet) {
|
|
|
|
|
return (xQueueReceive(motor_status_queue, status_packet, 0) == pdTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_motor_control(motor_control_group_t new_motor_control){
|
|
|
|
|
xQueueOverwrite(motor_control_queue, &new_motor_control);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void i2c_comms_task(void *pvParameters) {
|
|
|
|
|
uint8_t reply_bytecount;
|
|
|
|
|
motor_status_packet_t i2c_reply;
|
|
|
|
|
motor_write_packet_t motor_write_packet;
|
|
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
// Only need to run this task when there is something to do on the I2C bus
|
|
|
|
|
@ -51,6 +58,14 @@ static void i2c_comms_task(void *pvParameters) {
|
|
|
|
|
// I2C read error of some sort
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Send a motor control packet if requested
|
|
|
|
|
if (xQueueReceive(motor_control_queue, &motor_write_packet.control, 0)==pdTRUE){
|
|
|
|
|
motor_write_packet.packet_type = MOTOR_CONTROL_PACKET;
|
|
|
|
|
Wire.beginTransmission(MOTOR_ESP32_SLAVE_I2C_ADDR);
|
|
|
|
|
Wire.write((byte *)&motor_write_packet, sizeof(motor_write_packet));
|
|
|
|
|
Wire.endTransmission();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -61,6 +76,7 @@ void i2c_comms_setup(void) {
|
|
|
|
|
// Initialise our queues and semaphores
|
|
|
|
|
motor_status_semaphore = xSemaphoreCreateBinary();
|
|
|
|
|
motor_status_queue = xQueueCreate(1, sizeof(motor_status_packet_t));
|
|
|
|
|
motor_control_queue = xQueueCreate(1, sizeof(motor_control_group_t));
|
|
|
|
|
|
|
|
|
|
// Kick off our I2C comms task
|
|
|
|
|
xTaskCreate(i2c_comms_task, "MotorCtrl", I2C_TASK_STACK_SIZE, NULL, 5, &i2c_comms_task_handle);
|
|
|
|
|
|