DMX512, RDM send/recv library http://mbed.org/users/okini3939/notebook/dmx512

Dependents:   dmx_test ArtNodeLED SPK-DVIMXR SPK-DMXer ... more

DMX512 send/recv library

DMX512 is protocol for lighting.

調光プロトコル DMX512 を送受信するライブラリです。

see: http://mbed.org/users/okini3939/notebook/dmx512/

LPC1114 support is thanks to Stanly Chen

Files at this revision

API Documentation at this revision

Comitter:
okini3939
Date:
Mon Mar 11 04:02:26 2013 +0000
Parent:
7:16d6874076dd
Child:
9:e687f321c428
Commit message:
fix uart direct

Changed in this revision

DMX.cpp Show annotated file Show diff for this revision Revisions of this file
DMX.h Show annotated file Show diff for this revision Revisions of this file
--- a/DMX.cpp	Sun Jan 13 01:35:53 2013 +0000
+++ b/DMX.cpp	Mon Mar 11 04:02:26 2013 +0000
@@ -25,41 +25,21 @@
     is_sent = 0;
 
 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
-    if (p_tx == p9) {
-      uart_lcr = &LPC_UART3->LCR;
-      uart_thr = &LPC_UART3->THR;
-    } else
-    if (p_tx == p13) {
-      uart_lcr = &LPC_UART1->LCR;
-      uart_thr = &LPC_UART1->THR;
-    } else
-    if (p_tx == p28) {
-      uart_lcr = &LPC_UART2->LCR;
-      uart_thr = &LPC_UART2->THR;
-    }
     if (p_rx == p10) {
-      uart_lsr = &LPC_UART3->LSR;
-      uart_rbr = &LPC_UART3->RBR;
+      _uart = LPC_UART3;
       NVIC_SetPriority(UART3_IRQn, 1);
     } else
     if (p_rx == p14) {
-      uart_lsr = &LPC_UART1->LSR;
-      uart_rbr = &LPC_UART1->RBR;
+      _uart = (LPC_UART_TypeDef*)LPC_UART1;
       NVIC_SetPriority(UART1_IRQn, 1);
     } else
     if (p_rx == p27) {
-      uart_lsr = &LPC_UART2->LSR;
-      uart_rbr = &LPC_UART2->RBR;
+      _uart = LPC_UART2;
       NVIC_SetPriority(UART2_IRQn, 1);
     }
 #elif defined(TARGET_LPC11U24)
-    if (p_tx == p9) {
-      uart_lcr = &LPC_USART->LCR;
-      uart_thr = &LPC_USART->THR;
-    }
     if (p_rx == p10) {
-      uart_lsr = &LPC_USART->LSR;
-      uart_rbr = &LPC_USART->RBR;
+      _uart = LPC_USART;
       NVIC_SetPriority(UART_IRQn, 1);
     }
 #endif
@@ -99,7 +79,7 @@
     case DMX_MODE_BEGIN:
         // Break Time
         timeout01.detach();
-        *uart_lcr |= (1 << 6);
+        _uart->LCR |= (1 << 6);
         mode_tx = DMX_MODE_BREAK;
         timeout01.attach_us(this, &DMX::int_timer, DMX_TIME_BREAK);
         break;
@@ -107,7 +87,7 @@
     case DMX_MODE_BREAK:
         // Mark After Break
         timeout01.detach();
-        *uart_lcr &= ~(1 << 6);
+        _uart->LCR &= ~(1 << 6);
         mode_tx = DMX_MODE_MAB;
         timeout01.attach_us(this, &DMX::int_timer, DMX_TIME_MAB);
         break;
@@ -119,7 +99,7 @@
         mode_tx = DMX_MODE_DATA;
         _dmx.attach(this, &DMX::int_tx, Serial::TxIrq);
 #ifdef DMX_UART_DIRECT
-        *uart_thr = 0;
+        _uart->THR = 0;
 #else
         _dmx.putc(0);
 #endif
@@ -132,7 +112,7 @@
     if (mode_tx == DMX_MODE_DATA) {
         if (addr_tx < DMX_SIZE) {
 #ifdef DMX_UART_DIRECT
-            *uart_thr = (uint8_t)data_tx[addr_tx];
+            _uart->THR = (uint8_t)data_tx[addr_tx];
 #else
             _dmx.putc(data_tx[addr_tx]);
 #endif
@@ -149,16 +129,16 @@
 void DMX::int_rx () {
     int flg, dat;
 
-    flg = *uart_lsr;
+    flg = _uart->LSR;
 #ifdef DMX_UART_DIRECT
-    dat = *uart_rbr;
+    dat = _uart->RBR;
 #else
     dat = _dmx.getc();
 #endif
 
     if (flg & ((1 << 7)|(1 << 3)|(1 << 4))) {
         // Break Time
-        if (addr_rx > 0) {
+        if (addr_rx >= 24) {
             is_recived = 1;
         }
         mode_rx = DMX_MODE_BREAK;
--- a/DMX.h	Sun Jan 13 01:35:53 2013 +0000
+++ b/DMX.h	Mon Mar 11 04:02:26 2013 +0000
@@ -88,15 +88,9 @@
 
 private:
 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
-    __IO uint8_t *uart_lcr;
-    __I  uint8_t *uart_lsr;
-    __IO uint8_t *uart_thr;
-    __I  uint8_t *uart_rbr;
+    LPC_UART_TypeDef *_uart;
 #elif defined(TARGET_LPC11U24)
-    __IO uint32_t *uart_lcr;
-    __I  uint32_t *uart_lsr;
-    __IO uint32_t *uart_thr;
-    __I  uint32_t *uart_rbr;
+    LPC_USART_Type *_uart;
 #endif
 
 };