button remote working
This commit is contained in:
parent
6d1bf89e0e
commit
4b199e1fb4
5 changed files with 64 additions and 28 deletions
|
|
@ -11,6 +11,7 @@ struct st_7seg {
|
|||
int digit;
|
||||
int bit;
|
||||
uint16_t datagram;
|
||||
uint8_t buttons;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
#include <serial.h>
|
||||
|
||||
|
||||
#define PROTO_RESPONSE_TIMEOUT_MS 20
|
||||
#define PROTO_UPDATE_INTERVAL_MS 200
|
||||
#define PROTO_RESPONSE_TIMEOUT_MS 5
|
||||
#define PROTO_UPDATE_INTERVAL_MS 50
|
||||
|
||||
|
||||
enum proto_fsm {
|
||||
|
|
|
|||
|
|
@ -11,14 +11,14 @@ int bt_inputs() {
|
|||
bool bt1 = !!(GPIOB->IDR & (1<<1));
|
||||
bool bt2 = !!(GPIOB->IDR & (1<<0));
|
||||
bool bt3 = !!(GPIOB->IDR & (1<<12));
|
||||
bool bt4 = !!(GPIOB->IDR & (1<<4));
|
||||
bool bt4 = !!(GPIOB->IDR & (1<<3));
|
||||
bool bt5 = !!(GPIOA->IDR & (1<<15));
|
||||
return (bt5<<5) | (bt4<<4) | (bt3<<3) | (bt2<<2) | (bt1<<1) | (bt0<<0);
|
||||
}
|
||||
|
||||
void init_7seg() {
|
||||
GPIOA->MODER |= OUT(15);
|
||||
GPIOB->MODER |= OUT(12) | OUT(3);
|
||||
GPIOB->MODER |= OUT(12) | OUT(3) | OUT(2);
|
||||
GPIOA->BRR = (1<<15);
|
||||
GPIOB->BRR = (1<<12) | (1<<3);
|
||||
memset(&st_7seg, 0, sizeof(st_7seg));
|
||||
|
|
@ -122,32 +122,42 @@ static uint8_t led7seg_font_lut[] = {
|
|||
void step_7seg() {
|
||||
GPIOA->BSRR = BSRR_CLEAR(15);
|
||||
|
||||
if (st_7seg.bit&1) {
|
||||
GPIOB->BSRR = BSRR_SET(3);
|
||||
st_7seg.datagram <<= 1;
|
||||
} else {
|
||||
GPIOB->BSRR = BSRR_VALUE(12, st_7seg.datagram&0x8000) | BSRR_CLEAR(3);
|
||||
if (st_7seg.bit < 16*2) {
|
||||
if (st_7seg.bit&1) {
|
||||
GPIOB->BSRR = BSRR_SET(3);
|
||||
st_7seg.datagram <<= 1;
|
||||
} else {
|
||||
GPIOB->BSRR = BSRR_VALUE(12, st_7seg.datagram&0x8000) | BSRR_CLEAR(3);
|
||||
}
|
||||
}
|
||||
|
||||
st_7seg.bit++;
|
||||
if (st_7seg.bit == 16*2) {
|
||||
st_7seg.bit = 0;
|
||||
if (st_7seg.bit >= 16*2) {
|
||||
if (st_7seg.bit == 16*2+1) {
|
||||
st_7seg.bit = 0;
|
||||
st_7seg.buttons = bt_inputs();
|
||||
GPIOB->BSRR = (1<<2); /* Disable buttons */
|
||||
GPIOB->MODER |= OUT(3) | OUT(12);
|
||||
|
||||
st_7seg.module++;
|
||||
if (st_7seg.module == 3) {
|
||||
st_7seg.module = 0;
|
||||
GPIOA->BSRR = BSRR_SET(15);
|
||||
st_7seg.module++;
|
||||
if (st_7seg.module == 3) {
|
||||
st_7seg.module = 0;
|
||||
GPIOA->BSRR = BSRR_SET(15);
|
||||
|
||||
st_7seg.digit++;
|
||||
if (st_7seg.digit == 8) {
|
||||
st_7seg.digit = 0;
|
||||
st_7seg.digit++;
|
||||
if (st_7seg.digit == 8) {
|
||||
st_7seg.digit = 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t dp = (st_7seg.dp[st_7seg.module] & (1<<st_7seg.digit)) ? 0x80 : 0x00;
|
||||
st_7seg.datagram = ((st_7seg.digit+1)<<8) |
|
||||
led7seg_font_lut[st_7seg.data[st_7seg.module][st_7seg.digit]] |
|
||||
dp;
|
||||
} else {
|
||||
GPIOB->BRR = (1<<2); /* Enable buttons */
|
||||
GPIOB->MODER &= ~(CLEAR(3) | CLEAR(12));
|
||||
}
|
||||
|
||||
uint8_t dp = (st_7seg.dp[st_7seg.module] & (1<<st_7seg.digit)) ? 0x80 : 0x00;
|
||||
st_7seg.datagram = ((st_7seg.digit+1)<<8) |
|
||||
led7seg_font_lut[st_7seg.data[st_7seg.module][st_7seg.digit]] |
|
||||
dp;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
11
src/main.c
11
src/main.c
|
|
@ -150,7 +150,9 @@ int main(void) {
|
|||
(3<<GPIO_OSPEEDR_OSPEEDR15_Pos);
|
||||
GPIOB->PUPDR |= PULLUP(0) | /* BT2 */
|
||||
PULLUP(1) | /* BT1 */
|
||||
PULLUP(2); /* BT0 */
|
||||
PULLUP(2) | /* BT0 */
|
||||
PULLUP(3) | /* BT4 */
|
||||
PULLUP(12); /* BT3 */
|
||||
GPIOB->OTYPER = (1<<12) | (1<<3);
|
||||
|
||||
/* GPIOC:
|
||||
|
|
@ -161,11 +163,12 @@ int main(void) {
|
|||
|
||||
led_init();
|
||||
led_set_global_brightness(2);
|
||||
adc_init();
|
||||
lcd_init();
|
||||
|
||||
if (st_lcd.has_lcd) {
|
||||
uart_dma_init(USART3, DMA1_Channel7, BADDR_DISPLAY);
|
||||
SYSCFG->CFGR1 |= SYSCFG_CFGR1_USART3_DMA_RMP;
|
||||
uart_dma_init(USART3, DMA1_Channel2, BADDR_DISPLAY);
|
||||
|
||||
const char *lines[4] = {"Display initialized ",
|
||||
" ",
|
||||
"Waiting for ",
|
||||
|
|
@ -183,6 +186,8 @@ int main(void) {
|
|||
blank_7seg(2);
|
||||
|
||||
} else {
|
||||
adc_init();
|
||||
|
||||
int bt = bt_inputs();
|
||||
if (bt&1) {
|
||||
uart_dma_init(USART3, DMA1_Channel7, BADDR_MOTOR);
|
||||
|
|
|
|||
24
src/proto.c
24
src/proto.c
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
#include <proto.h>
|
||||
#include <adc.h>
|
||||
#include <led7seg.h>
|
||||
|
||||
static void tx_time_sync(void);
|
||||
static ErrorCode tx_fetch_adc(int index);
|
||||
|
|
@ -8,6 +9,7 @@ static void proto_handle_host(bool timeout);
|
|||
static void proto_update_lcd_strings(void);
|
||||
static ErrorCode tx_update_display(void);
|
||||
static void tx_adc_data(void);
|
||||
static void tx_button_state(void);
|
||||
|
||||
|
||||
struct proto_state st_proto;
|
||||
|
|
@ -55,7 +57,7 @@ void uart_handle_user_packet(struct ll_pkt *pkt, size_t len) {
|
|||
|
||||
} else if (board_config == BCFG_DISPLAY) {
|
||||
if (pkt->type == PK_DISPLAY_UPDATE) {
|
||||
/* ... */
|
||||
tx_button_state();
|
||||
}
|
||||
} else if (board_config == BCFG_MEAS) {
|
||||
if (pkt->type == PK_FETCH_ADC) {
|
||||
|
|
@ -114,7 +116,7 @@ void tx_adc_data() {
|
|||
.src = uart_st.addr,
|
||||
.dst = SER_ADDR_BROADCAST,
|
||||
.pid = 0,
|
||||
.type = PK_TIME_SYNC,
|
||||
.type = PK_FETCH_RESPONSE,
|
||||
},
|
||||
.timestamp = sync_time_us,
|
||||
.sampling_interval_us = st_adc.sampling_interval_us,
|
||||
|
|
@ -148,6 +150,24 @@ void tx_adc_data() {
|
|||
}
|
||||
}
|
||||
|
||||
void tx_button_state() {
|
||||
struct pkt_button_state pk = {
|
||||
.ll_pkt = {
|
||||
.src = uart_st.addr,
|
||||
.dst = SER_ADDR_BROADCAST,
|
||||
.pid = 0,
|
||||
.type = PK_BUTTON_STATE,
|
||||
},
|
||||
.buttons = st_7seg.buttons,
|
||||
};
|
||||
|
||||
ErrorCode rc = uart_send_packet_nonblocking(&pk.ll_pkt, sizeof(pk));
|
||||
if (rc) {
|
||||
st_proto.error = rc;
|
||||
st_proto.last_error = sys_time_us;
|
||||
}
|
||||
}
|
||||
|
||||
void tx_time_sync() {
|
||||
struct pkt_time_sync pk = {
|
||||
.ll_pkt = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue