#ifndef HOVERBOARD_H
#define HOVERBOARD_H

#include <stdint.h>

/*
 * Hoverboard ESC UART protocol (EFeru FOC firmware)
 * USART2: PA2=TX, PA3=RX @ 115200 baud
 *
 * Packet: [0xABCD] [steer:i16] [speed:i16] [checksum:u16]
 * Checksum = start ^ steer ^ speed
 * Speed range: -1000 to +1000
 * Must send at >=50Hz or ESC times out (TIMEOUT=20 * DELAY_IN_MAIN_LOOP=5ms = 100ms)
 */

#define HOVERBOARD_START_FRAME  0xABCD
#define HOVERBOARD_BAUD         38400

typedef struct __attribute__((packed)) {
    uint16_t start;
    int16_t  steer;
    int16_t  speed;
    uint16_t checksum;
} hoverboard_cmd_t;

void hoverboard_init(void);
void hoverboard_send(int16_t speed, int16_t steer);

#endif
