diff options
author | David Lamparter <equinox@diac24.net> | 2012-05-12 19:36:58 +0200 |
---|---|---|
committer | David Lamparter <equinox@diac24.net> | 2012-05-12 19:36:58 +0200 |
commit | 3ae67269dc61d0ebb2b0a8c78af8fc4348755afb (patch) | |
tree | d4a1a9073ec2279ac234448e6e56618b66a55b88 /dali.c | |
parent | abd5066a4950da393417ce520788c018d618488e (diff) |
dali: more improvements
Diffstat (limited to 'dali.c')
-rw-r--r-- | dali.c | 35 |
1 files changed, 34 insertions, 1 deletions
@@ -1,9 +1,17 @@ +/* invalid command, used as default/do-nothing value + * 101CCCCX == special commands, X must be 1. + * X is 0 below => invalid + */ +#define DALI_INVALID 0xa000 + static uint16_t dali_word, dali_sendq; static uint8_t dali_subctr, dali_state, dali_bit; static uint8_t dali_prevpin; enum dali_state { DALI_IDLE = 0, + DALI_TX_SPACE, + DALI_TX_STARTBIT1, DALI_TX_STARTBIT2, @@ -22,7 +30,7 @@ ISR(TIMER0_COMPA_vect) TCNT0 = 0; /* CTC mode didn't work, CBA to debug */ data = (PIND >> D_DALII) & 1; - if (dali_state == DALI_IDLE && data) { + if (dali_state <= DALI_TX_SPACE && data) { dali_state = DALI_RX_LEFT; dali_subctr = 4; dali_word = 1; @@ -48,6 +56,18 @@ ISR(TIMER0_COMPA_vect) switch (dali_state) { /* idle */ case DALI_IDLE: + if (dali_sendq != DALI_INVALID) { + dali_word = dali_sendq; + dali_sendq = DALI_INVALID; + dali_state = DALI_TX_STARTBIT1; + } + return; + + case DALI_TX_SPACE: + /* 12 ms inter-command spacing */ + if (dali_bit > 28) + dali_state = DALI_IDLE; + dali_bit++; return; /* write */ @@ -109,6 +129,19 @@ ISR(TIMER0_COMPA_vect) } } +static void dali_send(uint16_t word) +{ + cli(); + dali_sendq = word; + sei(); +} + +static bool dali_queue_busy(void) +{ + asm volatile ("" : : : "memory"); + return dali_sendq != DALI_INVALID; +} + static void dali_init(void) { PORTD |= (1 << D_DALII); |