An initial port to the FRDM-K46Z based on the the following: https://developer.mbed.org/users/okini3939/notebook/dmx512/

Dependents:   FRDM-Dowser

Fork of DMX by Suga koubou

Need to update the UART references to the K46Z. The KE02 Sub-Family Reference Manual provides us with the required information.

The modifications are wrapped with the target for the K46: For example, defined(TARGET_KL46Z)

Revision:
16:84a017ef96f8
Parent:
15:4ea4a31c7609
Child:
17:12dd79109ce3
--- a/DMX.cpp	Tue Aug 26 13:25:24 2014 +0000
+++ b/DMX.cpp	Thu Mar 05 21:28:02 2015 +0000
@@ -37,6 +37,20 @@
       _uart = LPC_UART3;
       NVIC_SetPriority(UART3_IRQn, 1);
     }
+#elif defined(TARGET_KL46Z)
+    if ((p_rx == PTE21) || (p_rx == PTA1)){
+      _uart = (UARTLP_Type *)UART0;
+      NVIC_SetPriority(UART0_IRQn, 1);
+    } else
+    if (p_rx == PTE1) {
+      _uart = (UARTLP_Type *)UART1;
+      NVIC_SetPriority(UART1_IRQn, 1);
+    } else
+    if ((p_rx == PTE23) || (p_rx == PTE17)) {
+      _uart = (UARTLP_Type *)UART2;
+      NVIC_SetPriority(UART2_IRQn, 1);
+    } else
+   
 #elif defined(TARGET_LPC4088)
     if (p_rx == p10) {
       _uart = LPC_UART3;
@@ -94,7 +108,11 @@
     case DMX_MODE_BEGIN:
         // Break Time
         timeout01.detach();
-        _uart->LCR |= (1 << 6);
+        #if defined(TARGET_KL46Z)
+            _uart->C2 |= UART_C2_SBK_MASK | UART_C2_TE_MASK | UART_C2_RE_MASK;
+        #else
+            _uart->LCR |= (1 << 6);
+        #endif
         mode_tx = DMX_MODE_BREAK;
         timeout01.attach_us(this, &DMX::int_timer, DMX_TIME_BREAK);
         break;
@@ -102,7 +120,11 @@
     case DMX_MODE_BREAK:
         // Mark After Break
         timeout01.detach();
+        #if defined(TARGET_KL46Z)
+        _uart->C2 &= ~UART_C2_SBK_MASK;
+        #else
         _uart->LCR &= ~(1 << 6);
+        #endif
         mode_tx = DMX_MODE_MAB;
         timeout01.attach_us(this, &DMX::int_timer, DMX_TIME_MAB);
         break;
@@ -114,8 +136,15 @@
         mode_tx = DMX_MODE_DATA;
         _dmx.attach(this, &DMX::int_tx, Serial::TxIrq);
 #ifdef DMX_UART_DIRECT
+        
+        
+        #if defined(TARGET_KL46Z)
+        while(!(_uart->S1 & UART_S1_TDRE_MASK));
+        _uart->D = DMX_START_CODE; // Freescale
+        #else
         while(!(_uart->LSR & (1<<5)));
         _uart->THR = DMX_START_CODE;
+        #endif
 #else
         _dmx.putc(DMX_START_CODE);
 #endif
@@ -128,7 +157,12 @@
     if (mode_tx == DMX_MODE_DATA) {
         if (addr_tx < DMX_SIZE) {
 #ifdef DMX_UART_DIRECT
+            
+            #if defined(TARGET_KL46Z)
+            _uart->D = (uint8_t)data_tx[addr_tx]; // Freescale
+            #else
             _uart->THR = (uint8_t)data_tx[addr_tx];
+            #endif
 #else
             _dmx.putc(data_tx[addr_tx]);
 #endif
@@ -144,10 +178,23 @@
 
 void DMX::int_rx () {
     int flg, dat;
-
-    flg = _uart->LSR;
+    int tmp1,tmp2;
+    #if defined(TARGET_KL46Z)  // looking for (7)errornous data,(3) Framming Error, (4) Break
+    tmp1 = (_uart->S1 & (UART_S1_NF_MASK|UART_S1_FE_MASK));         // NF,FE
+    tmp2 = (_uart->S2 & UART_S2_LBKDIF_MASK);         //LBKDIF
+    flg = (tmp1<<1) | tmp2;
+    #else
+    flg = _uart->LSR;  
+    #endif
+    
 #ifdef DMX_UART_DIRECT
+    #if defined(TARGET_KL46Z)
+    dat = _uart->D;  // Freescale
+    #else
     dat = _uart->RBR;
+    #endif
+      
+   
 #else
     dat = _dmx.getc();
 #endif