diff options
-rw-r--r-- | can.c | 24 | ||||
-rw-r--r-- | lightctrl.c | 26 |
2 files changed, 42 insertions, 8 deletions
@@ -135,10 +135,15 @@ static void can_send(uint32_t daddr, uint8_t len, uint8_t *data) } #ifndef R0KET +union { + uint8_t b[4]; + uint32_t u; +} can_rx_addr; +uint8_t can_rx_dlc, can_rx_data[8]; + static void can_rxh(uint8_t buffer) { - uint8_t dlc, c, rtr; - uint32_t addr; + uint8_t c, byte; if (buffer) uart_puts("can: RX1IF\n"); @@ -146,17 +151,20 @@ static void can_rxh(uint8_t buffer) uart_puts("can: RX0IF\n"); spi_ss(0); spi_wrrd(0x90 + 0x04 * buffer); - addr = 0; -#define rdaddr() c = spi_wrrd(0xff); uart_puthex(c); addr <<= 8; addr |= c + c = 0; +#define rdaddr() byte = spi_wrrd(0xff); uart_puthex(byte); can_rx_addr.b[c++] = byte rdaddr(); rdaddr(); rdaddr(); rdaddr(); - dlc = spi_wrrd(0xff); - uart_puthex(dlc); + can_rx_dlc = spi_wrrd(0xff); + uart_puthex(can_rx_dlc); uart_puts("\n"); - for (c = 0; c < (dlc & 0x0f); c++) - uart_puthex(spi_wrrd(0xff)); + for (c = 0; c < (can_rx_dlc & 0x0f); c++) { + byte = spi_wrrd(0xff); + can_rx_data[c] = byte; + uart_puthex(byte); + } uart_puts("\n"); spi_ss(1); } diff --git a/lightctrl.c b/lightctrl.c index 464a0ae..404ca33 100644 --- a/lightctrl.c +++ b/lightctrl.c @@ -27,6 +27,27 @@ const uint8_t __signature[3] __attribute__((section (".signature"), used)) = #include "dim.c" #include "can.c" +static void can_rx_exec(void) +{ + if (can_rx_addr.b[0] == 0xcc + && (can_rx_addr.b[1] & 0xfb) == 0x08 + && can_rx_addr.b[2] == 0x04 + && can_rx_addr.b[3] == 0x7f + && (can_rx_dlc & 0x4f) == 1) { + uart_puts("-- SET\n"); + + if (!can_rx_data[0]) { + dim_state = 0; + dali_send(DALI_ADDR | 0x100); + } else { + if (!dim_state && can_rx_data[0]) + dali_send(DALI_ADDR | 0x108); + dim_state = can_rx_data[0]; + dali_send(DALI_ADDR | dim_state); + } + } +} + int main(void) { DDRD |= (1 << D_LED1) | (1 << D_LED2 ) | (1 << D_TXD) | (1 << D_DALIO); @@ -51,6 +72,11 @@ int main(void) if (canint) { canint = false; can_int(); + + if (can_rx_addr.b[0]) { + can_rx_exec(); + can_rx_addr.u = 0; + } } _delay_ms(5); do_tick(); |