DMX library

Fork of DMX by Suga koubou

Committer:
okini3939
Date:
Fri Sep 28 03:31:02 2012 +0000
Revision:
3:2eb66b4d99bd
Parent:
1:f0d988e15810
Child:
4:dd0544c80096
fix reset

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okini3939 0:cbff6bf41542 1 /*
okini3939 0:cbff6bf41542 2 * DMX512 send/recv library
okini3939 0:cbff6bf41542 3 * Copyright (c) 2011 Hiroshi Suga
okini3939 0:cbff6bf41542 4 * Released under the MIT License: http://mbed.org/license/mit
okini3939 0:cbff6bf41542 5 */
okini3939 0:cbff6bf41542 6
okini3939 0:cbff6bf41542 7 /** @file DMX.h
okini3939 0:cbff6bf41542 8 * @brief DMX512 send/recv
okini3939 0:cbff6bf41542 9 */
okini3939 0:cbff6bf41542 10
okini3939 0:cbff6bf41542 11 #ifndef DMX_H
okini3939 0:cbff6bf41542 12 #define DMX_H
okini3939 0:cbff6bf41542 13
okini3939 0:cbff6bf41542 14 #include "mbed.h"
okini3939 0:cbff6bf41542 15
okini3939 1:f0d988e15810 16 #define DMX_UART_DIRECT
okini3939 0:cbff6bf41542 17
okini3939 0:cbff6bf41542 18 #define DMX_SIZE 512
okini3939 0:cbff6bf41542 19 #define DMX_TIME_BREAK 100 // 100us
okini3939 0:cbff6bf41542 20 #define DMX_TIME_MAB 10 // 10us
okini3939 0:cbff6bf41542 21 #define DMX_TIME_BETWEEN 10 // 10us
okini3939 0:cbff6bf41542 22
okini3939 0:cbff6bf41542 23 enum DMX_MODE {
okini3939 0:cbff6bf41542 24 DMX_MODE_BEGIN,
okini3939 0:cbff6bf41542 25 DMX_MODE_START,
okini3939 0:cbff6bf41542 26 DMX_MODE_BREAK,
okini3939 0:cbff6bf41542 27 DMX_MODE_MAB,
okini3939 0:cbff6bf41542 28 DMX_MODE_DATA,
okini3939 0:cbff6bf41542 29 DMX_MODE_ERROR,
okini3939 0:cbff6bf41542 30 };
okini3939 0:cbff6bf41542 31
okini3939 0:cbff6bf41542 32 /** DMX512 class (sender/client)
okini3939 0:cbff6bf41542 33 */
okini3939 0:cbff6bf41542 34 class DMX {
okini3939 0:cbff6bf41542 35 public:
okini3939 0:cbff6bf41542 36 /** init DMX class
okini3939 0:cbff6bf41542 37 * @param p_tx TX serial port (p9, p13, p28)
okini3939 0:cbff6bf41542 38 * @param p_rx RX serial port (p10, p14, p27)
okini3939 0:cbff6bf41542 39 */
okini3939 0:cbff6bf41542 40 DMX (PinName p_tx, PinName p_rx);
okini3939 0:cbff6bf41542 41
okini3939 0:cbff6bf41542 42 /** Send the message
okini3939 0:cbff6bf41542 43 * @param ch DMX data address (0-511)
okini3939 0:cbff6bf41542 44 * @param data DMX data (0-255)
okini3939 0:cbff6bf41542 45 */
okini3939 0:cbff6bf41542 46 void put (int ch, int data);
okini3939 0:cbff6bf41542 47
okini3939 0:cbff6bf41542 48 /** Send the message
okini3939 0:cbff6bf41542 49 * @param ch DMX data address (0-511)
okini3939 0:cbff6bf41542 50 * @return DMX data (0-255)
okini3939 0:cbff6bf41542 51 */
okini3939 0:cbff6bf41542 52 int get (int ch);
okini3939 0:cbff6bf41542 53
okini3939 3:2eb66b4d99bd 54 void reset ();
okini3939 3:2eb66b4d99bd 55
okini3939 0:cbff6bf41542 56 volatile int is_recived, is_sent;
okini3939 0:cbff6bf41542 57
okini3939 0:cbff6bf41542 58 protected:
okini3939 0:cbff6bf41542 59
okini3939 0:cbff6bf41542 60 void int_timer ();
okini3939 0:cbff6bf41542 61 void int_tx ();
okini3939 0:cbff6bf41542 62 void int_rx ();
okini3939 0:cbff6bf41542 63
okini3939 0:cbff6bf41542 64 Serial dmx;
okini3939 0:cbff6bf41542 65 Timeout timeout01;
okini3939 0:cbff6bf41542 66 __IO uint8_t *uart_lcr;
okini3939 0:cbff6bf41542 67 __I uint8_t *uart_lsr;
okini3939 0:cbff6bf41542 68 __IO uint8_t *uart_thr;
okini3939 0:cbff6bf41542 69 __I uint8_t *uart_rbr;
okini3939 0:cbff6bf41542 70 volatile DMX_MODE mode_tx, mode_rx;
okini3939 0:cbff6bf41542 71 volatile int addr_tx, addr_rx;
okini3939 0:cbff6bf41542 72 unsigned char data_tx[DMX_SIZE];
okini3939 0:cbff6bf41542 73 unsigned char data_rx[DMX_SIZE];
okini3939 0:cbff6bf41542 74
okini3939 0:cbff6bf41542 75 private:
okini3939 0:cbff6bf41542 76
okini3939 0:cbff6bf41542 77 };
okini3939 0:cbff6bf41542 78
okini3939 0:cbff6bf41542 79 #endif