summaryrefslogtreecommitdiff
path: root/dali2.c
diff options
context:
space:
mode:
Diffstat (limited to 'dali2.c')
-rw-r--r--dali2.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/dali2.c b/dali2.c
index ee00c1b..57bd72f 100644
--- a/dali2.c
+++ b/dali2.c
@@ -64,6 +64,8 @@ ISR(TIMER0_COMPA_vect)
subsamp++;
subsamp &= 7;
+ while (TCNT0 < 52)
+ asm volatile ("nop\n" ::: "memory");
/* CTC mode didn't work, CBA to debug */
TCNT0 = 0;
@@ -198,6 +200,18 @@ ISR(TIMER0_COMPA_vect)
}
}
+#ifdef DALI_USER_IDLE
+ if (dali_state == DALI_IDLE && !dali_tx_rq) {
+ uint16_t next = dali_user_idle();
+ if (next != DALI_INVALID) {
+ tx_data = next;
+ bitpos = 0;
+ dali_state = DALI_TX_SBIT0;
+ subsamp = 7;
+ }
+ }
+#endif
+
if (dali_state == DALI_IDLE && dali_tx_rq) {
tx_data = dali_tx;
bitpos = 0;
@@ -221,7 +235,10 @@ static void dali_send(uint16_t word)
dali_rx_avail = 0;
dali_tx = word;
- asm volatile ("" ::: "memory");
+
+ do asm volatile ("" ::: "memory");
+ while (dali_tx_rq);
+
dali_tx_rq = 1;
while (dali_tx_rq || dali_state != DALI_IDLE) {
asm volatile ("" ::: "memory");
@@ -273,7 +290,7 @@ static void dali_init(void)
TIFR0 = (1 << OCF0A);
TCNT0 = 0;
- OCR0A = 52; // 8 MHz / 8 / 52 = 19230.
+ OCR0A = 49; /*52*/ // 8 MHz / 8 / 52 = 19230.
asm volatile ("" ::: "memory");
TIMSK0 = (1 << OCIE0A);
TCCR0A = 0;