Commits (1)
......@@ -15,7 +15,7 @@
#include "main.h"
#include "oled.h"
uint8_t dbus_buf[DBUS_BUFLEN];
rc_info_t rc;
RC_ctrl_t rc_ctrl;
/**
......@@ -79,27 +79,27 @@ uint16_t dma_current_data_counter(DMA_Stream_TypeDef *dma_stream)
* @param[in] buff: the buff which saved raw rc data
* @retval
*/
void rc_callback_handler(rc_info_t *rc, uint8_t *buff)
void rc_callback_handler(RC_ctrl_t *rc_ctrl, uint8_t *buff)
{
rc->ch4 = (buff[0] | buff[1] << 8) & 0x07FF; //0x07FF met la commande sur 11 bits (donc 2048 max)
rc->ch4 -= 1024; //on centre sur 0
rc->ch3 = (buff[1] >> 3 | buff[2] << 5) & 0x07FF;
rc->ch3 -= 1024;
rc->ch2 = (buff[2] >> 6 | buff[3] << 2 | buff[4] << 10) & 0x07FF;
rc->ch2 -= 1024;
rc->ch1 = (buff[4] >> 1 | buff[5] << 7) & 0x07FF;
rc->ch1 -= 1024;
rc->sw1 = ((buff[5] >> 4) & 0x000C) >> 2;
rc->sw2 = (buff[5] >> 4) & 0x0003;
rc_ctrl->rc.ch[3] = (buff[0] | buff[1] << 8) & 0x07FF; //0x07FF met la commande sur 11 bits (donc 2048 max)
rc_ctrl->rc.ch[3] -= 1024; //on centre sur 0
rc_ctrl->rc.ch[2] = (buff[1] >> 3 | buff[2] << 5) & 0x07FF;
rc_ctrl->rc.ch[2] -= 1024;
rc_ctrl->rc.ch[1] = (buff[2] >> 6 | buff[3] << 2 | buff[4] << 10) & 0x07FF;
rc_ctrl->rc.ch[1] -= 1024;
rc_ctrl->rc.ch[0] = (buff[4] >> 1 | buff[5] << 7) & 0x07FF;
rc_ctrl->rc.ch[0] -= 1024;
rc_ctrl->rc.sw[0] = ((buff[5] >> 4) & 0x000C) >> 2;
rc_ctrl->rc.sw[1] = (buff[5] >> 4) & 0x0003;
if ((abs(rc->ch1) > 660) || \
(abs(rc->ch2) > 660) || \
(abs(rc->ch3) > 660) || \
(abs(rc->ch4) > 660))
if ((abs(rc_ctrl->rc.ch[0]) > 660) || \
(abs(rc_ctrl->rc.ch[1]) > 660) || \
(abs(rc_ctrl->rc.ch[2]) > 660) || \
(abs(rc_ctrl->rc.ch[3]) > 660))
{
memset(rc, 0, sizeof(rc_info_t));
memset(&rc_ctrl->rc, 0, sizeof(rc_ctrl->rc));
}
}
......@@ -123,7 +123,7 @@ static void uart_rx_idle_callback(UART_HandleTypeDef* huart)
/* handle dbus data dbus_buf from DMA */
if ((DBUS_MAX_LEN - dma_current_data_counter(huart->hdmarx->Instance)) == DBUS_BUFLEN)
{
rc_callback_handler(&rc, dbus_buf);
rc_callback_handler(&rc_ctrl, dbus_buf);
}
/* restart dma transmission */
......
......@@ -18,21 +18,70 @@
#define DBUS_MAX_LEN (50)
#define DBUS_BUFLEN (18)
#define DBUS_HUART huart1 /* for dji remote controler reciever */
/* ----------------------- RC Switch Definition----------------------------- */
#define RC_SW_UP ((uint16_t)1)
#define RC_SW_MID ((uint16_t)3)
#define RC_SW_DOWN ((uint16_t)2)
#define switch_is_down(s) (s == RC_SW_DOWN)
#define switch_is_mid(s) (s == RC_SW_MID)
#define switch_is_up(s) (s == RC_SW_UP)
/* ----------------------- PC Key Definition-------------------------------- */
#define KEY_PRESSED_OFFSET_W ((uint16_t)1 << 0)
#define KEY_PRESSED_OFFSET_S ((uint16_t)1 << 1)
#define KEY_PRESSED_OFFSET_A ((uint16_t)1 << 2)
#define KEY_PRESSED_OFFSET_D ((uint16_t)1 << 3)
#define KEY_PRESSED_OFFSET_SHIFT ((uint16_t)1 << 4)
#define KEY_PRESSED_OFFSET_CTRL ((uint16_t)1 << 5)
#define KEY_PRESSED_OFFSET_Q ((uint16_t)1 << 6)
#define KEY_PRESSED_OFFSET_E ((uint16_t)1 << 7)
#define KEY_PRESSED_OFFSET_R ((uint16_t)1 << 8)
#define KEY_PRESSED_OFFSET_F ((uint16_t)1 << 9)
#define KEY_PRESSED_OFFSET_G ((uint16_t)1 << 10)
#define KEY_PRESSED_OFFSET_Z ((uint16_t)1 << 11)
#define KEY_PRESSED_OFFSET_X ((uint16_t)1 << 12)
#define KEY_PRESSED_OFFSET_C ((uint16_t)1 << 13)
#define KEY_PRESSED_OFFSET_V ((uint16_t)1 << 14)
#define KEY_PRESSED_OFFSET_B ((uint16_t)1 << 15)
/* ----------------------- Data Struct ------------------------------------- */
typedef __packed struct
{
__packed struct
{
int16_t ch[5];
char sw[2];
} rc;
__packed struct
{
int16_t x;
int16_t y;
int16_t z;
uint8_t press_l;
uint8_t press_r;
} mouse;
__packed struct
{
uint16_t v;
} key;
} RC_ctrl_t;
/**
* @brief remote control information
*/
typedef __packed struct
{
/* rocker channel information */
int16_t ch1;
int16_t ch2;
int16_t ch3;
int16_t ch4;
/* left and right lever information */
uint8_t sw1;
uint8_t sw2;
} rc_info_t;
//typedef __packed struct
//{
// /* rocker channel information */
// int16_t ch1;
// int16_t ch2;
// int16_t ch3;
// int16_t ch4;
// /* left and right lever information */
// uint8_t sw1;
// uint8_t sw2;
//} rc_info_t;
void uart_receive_handler(UART_HandleTypeDef *huart);
void dbus_uart_init(void);
......