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)

DMX.h

Committer:
rosienej
Date:
2015-03-27
Revision:
21:59c200304b47
Parent:
19:8a86e35e54a9

File content as of revision 21:59c200304b47:

/*
 * DMX512 send/recv library
 * Copyright (c) 2013 Hiroshi Suga
 * Released under the MIT License: http://mbed.org/license/mit
 */

/** @file
 * @brief DMX512 send/recv
 */
 


#ifndef DMX_H
#define DMX_H

#include "mbed.h"
#include "RawSerial.h"


#define DMX_UART_DIRECT

#define DMX_SIZE 512
#define DMX_TIME_BREAK 100 // 100us (88us-1s)
#define DMX_TIME_MAB 10 // 10us (8us-1s)
#define DMX_TIME_BETWEEN 200 // 10us (0-1s)
#define DMX_START_CODE 0

enum DMX_MODE {
    DMX_MODE_BEGIN,
    DMX_MODE_START,
    DMX_MODE_BREAK,
    DMX_MODE_MAB,
    DMX_MODE_DATA,
    DMX_MODE_ERROR,
    DMX_MODE_STOP,
};

/** DMX512 class (sender/client)
 */
class DMX {
public:
    /** init DMX class
     * @param p_tx TX serial port (p9, p13, p28)
     * @param p_rx RX serial port (p10, p14, p27)
     */
    DMX (PinName p_tx, PinName p_rx); 

    /** Send the data
     * @param addr DMX data address (0-511)
     * @param data DMX data (0-255)
     */
    void put (int addr, int data);
    /** Send the data
     * @param buf DMX data buffer
     * @param addr DMX data address
     * @param len data length
     */
    void put (unsigned char *buf, int addr = 0, int len = DMX_SIZE);

    /** Send the data
     * @param addr DMX data address (0-511)
     * @return DMX data (0-255)
     */
    int get (int addr);
    /** Send the data
     * @param buf DMX data buffer
     * @param addr DMX data address
     * @param len data length
     */
    void get (unsigned char *buf, int addr = 0, int len = DMX_SIZE);

    /** Start DMX send operation
     */
    void start ();
    /** Stop DMX send operation
     */
    void stop ();
    /** Clear DMX data
     */
    void clear ();
    
    /** Get the receiver Mode
     */
    int get_mode_rx(){return mode_rx;}

    volatile int is_recived, is_sent;

protected:

    void int_timer ();
    void int_tx ();
    void int_rx ();

//    Serial _dmx;
    RawSerial _dmx;
    Timeout timeout01;
    volatile DMX_MODE mode_tx, mode_rx;
    volatile int addr_tx, addr_rx;
    unsigned char data_tx[DMX_SIZE];
    unsigned char data_rx[DMX_SIZE];

private:
    
#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC4088)
    LPC_UART_TypeDef *_uart;
#elif defined(TARGET_LPC11UXX)
    LPC_USART_Type *_uart;
#elif defined(TARGET_LPC11XX)
    LPC_UART_TypeDef *_uart;
#elif defined(TARGET_KL46Z)
/**
    The UART type changes for the Freescale KL46Z
*/
    UARTLP_Type *_uart;
#else
    #error "this CPU not supported."
#endif

};

#endif