Add support new target MCU: LPC1114FN28 or LPC11XX
Fork of DMX by
DMX.h@5:72039cd4c874, 2013-01-04 (annotated)
- Committer:
- okini3939
- Date:
- Fri Jan 04 04:31:53 2013 +0000
- Revision:
- 5:72039cd4c874
- Parent:
- 4:dd0544c80096
- Child:
- 6:9e7b4eeac6ec
support LPC11U24
Who changed what in which revision?
User | Revision | Line number | New 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 | 4:dd0544c80096 | 30 | DMX_MODE_STOP, |
okini3939 | 0:cbff6bf41542 | 31 | }; |
okini3939 | 0:cbff6bf41542 | 32 | |
okini3939 | 0:cbff6bf41542 | 33 | /** DMX512 class (sender/client) |
okini3939 | 0:cbff6bf41542 | 34 | */ |
okini3939 | 0:cbff6bf41542 | 35 | class DMX { |
okini3939 | 0:cbff6bf41542 | 36 | public: |
okini3939 | 0:cbff6bf41542 | 37 | /** init DMX class |
okini3939 | 0:cbff6bf41542 | 38 | * @param p_tx TX serial port (p9, p13, p28) |
okini3939 | 0:cbff6bf41542 | 39 | * @param p_rx RX serial port (p10, p14, p27) |
okini3939 | 0:cbff6bf41542 | 40 | */ |
okini3939 | 0:cbff6bf41542 | 41 | DMX (PinName p_tx, PinName p_rx); |
okini3939 | 0:cbff6bf41542 | 42 | |
okini3939 | 0:cbff6bf41542 | 43 | /** Send the message |
okini3939 | 0:cbff6bf41542 | 44 | * @param ch DMX data address (0-511) |
okini3939 | 0:cbff6bf41542 | 45 | * @param data DMX data (0-255) |
okini3939 | 0:cbff6bf41542 | 46 | */ |
okini3939 | 0:cbff6bf41542 | 47 | void put (int ch, int data); |
okini3939 | 0:cbff6bf41542 | 48 | |
okini3939 | 0:cbff6bf41542 | 49 | /** Send the message |
okini3939 | 0:cbff6bf41542 | 50 | * @param ch DMX data address (0-511) |
okini3939 | 0:cbff6bf41542 | 51 | * @return DMX data (0-255) |
okini3939 | 0:cbff6bf41542 | 52 | */ |
okini3939 | 0:cbff6bf41542 | 53 | int get (int ch); |
okini3939 | 0:cbff6bf41542 | 54 | |
okini3939 | 4:dd0544c80096 | 55 | /** Start DMX send |
okini3939 | 4:dd0544c80096 | 56 | */ |
okini3939 | 4:dd0544c80096 | 57 | void start (); |
okini3939 | 4:dd0544c80096 | 58 | /** Stop DMX send |
okini3939 | 4:dd0544c80096 | 59 | */ |
okini3939 | 4:dd0544c80096 | 60 | void stop (); |
okini3939 | 3:2eb66b4d99bd | 61 | |
okini3939 | 0:cbff6bf41542 | 62 | volatile int is_recived, is_sent; |
okini3939 | 0:cbff6bf41542 | 63 | |
okini3939 | 0:cbff6bf41542 | 64 | protected: |
okini3939 | 0:cbff6bf41542 | 65 | |
okini3939 | 0:cbff6bf41542 | 66 | void int_timer (); |
okini3939 | 0:cbff6bf41542 | 67 | void int_tx (); |
okini3939 | 0:cbff6bf41542 | 68 | void int_rx (); |
okini3939 | 0:cbff6bf41542 | 69 | |
okini3939 | 5:72039cd4c874 | 70 | Serial _dmx; |
okini3939 | 0:cbff6bf41542 | 71 | Timeout timeout01; |
okini3939 | 5:72039cd4c874 | 72 | #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) |
okini3939 | 0:cbff6bf41542 | 73 | __IO uint8_t *uart_lcr; |
okini3939 | 0:cbff6bf41542 | 74 | __I uint8_t *uart_lsr; |
okini3939 | 0:cbff6bf41542 | 75 | __IO uint8_t *uart_thr; |
okini3939 | 0:cbff6bf41542 | 76 | __I uint8_t *uart_rbr; |
okini3939 | 5:72039cd4c874 | 77 | #elif defined(TARGET_LPC11U24) |
okini3939 | 5:72039cd4c874 | 78 | __IO uint32_t *uart_lcr; |
okini3939 | 5:72039cd4c874 | 79 | __I uint32_t *uart_lsr; |
okini3939 | 5:72039cd4c874 | 80 | __IO uint32_t *uart_thr; |
okini3939 | 5:72039cd4c874 | 81 | __I uint32_t *uart_rbr; |
okini3939 | 5:72039cd4c874 | 82 | #endif |
okini3939 | 0:cbff6bf41542 | 83 | volatile DMX_MODE mode_tx, mode_rx; |
okini3939 | 0:cbff6bf41542 | 84 | volatile int addr_tx, addr_rx; |
okini3939 | 0:cbff6bf41542 | 85 | unsigned char data_tx[DMX_SIZE]; |
okini3939 | 0:cbff6bf41542 | 86 | unsigned char data_rx[DMX_SIZE]; |
okini3939 | 0:cbff6bf41542 | 87 | |
okini3939 | 0:cbff6bf41542 | 88 | private: |
okini3939 | 0:cbff6bf41542 | 89 | |
okini3939 | 0:cbff6bf41542 | 90 | }; |
okini3939 | 0:cbff6bf41542 | 91 | |
okini3939 | 0:cbff6bf41542 | 92 | #endif |