DMX library
Fork of DMX by
DMX.h@7:16d6874076dd, 2013-01-13 (annotated)
- Committer:
- okini3939
- Date:
- Sun Jan 13 01:35:53 2013 +0000
- Revision:
- 7:16d6874076dd
- Parent:
- 6:9e7b4eeac6ec
- Child:
- 8:d4a45bba41d2
fix;
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 | 6:9e7b4eeac6ec | 3 | * Copyright (c) 2013 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 | 7:16d6874076dd | 7 | /** @file |
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 | 6:9e7b4eeac6ec | 43 | /** Send the data |
okini3939 | 6:9e7b4eeac6ec | 44 | * @param addr DMX data address (0-511) |
okini3939 | 0:cbff6bf41542 | 45 | * @param data DMX data (0-255) |
okini3939 | 0:cbff6bf41542 | 46 | */ |
okini3939 | 6:9e7b4eeac6ec | 47 | void put (int addr, int data); |
okini3939 | 6:9e7b4eeac6ec | 48 | /** Send the data |
okini3939 | 6:9e7b4eeac6ec | 49 | * @param buf DMX data buffer |
okini3939 | 6:9e7b4eeac6ec | 50 | * @param addr DMX data address |
okini3939 | 6:9e7b4eeac6ec | 51 | * @param len data length |
okini3939 | 6:9e7b4eeac6ec | 52 | */ |
okini3939 | 6:9e7b4eeac6ec | 53 | void put (unsigned char *buf, int addr = 0, int len = DMX_SIZE); |
okini3939 | 0:cbff6bf41542 | 54 | |
okini3939 | 6:9e7b4eeac6ec | 55 | /** Send the data |
okini3939 | 7:16d6874076dd | 56 | * @param addr DMX data address (0-511) |
okini3939 | 0:cbff6bf41542 | 57 | * @return DMX data (0-255) |
okini3939 | 0:cbff6bf41542 | 58 | */ |
okini3939 | 6:9e7b4eeac6ec | 59 | int get (int addr); |
okini3939 | 6:9e7b4eeac6ec | 60 | /** Send the data |
okini3939 | 6:9e7b4eeac6ec | 61 | * @param buf DMX data buffer |
okini3939 | 6:9e7b4eeac6ec | 62 | * @param addr DMX data address |
okini3939 | 6:9e7b4eeac6ec | 63 | * @param len data length |
okini3939 | 6:9e7b4eeac6ec | 64 | */ |
okini3939 | 6:9e7b4eeac6ec | 65 | void get (unsigned char *buf, int addr = 0, int len = DMX_SIZE); |
okini3939 | 0:cbff6bf41542 | 66 | |
okini3939 | 6:9e7b4eeac6ec | 67 | /** Start DMX send operation |
okini3939 | 4:dd0544c80096 | 68 | */ |
okini3939 | 4:dd0544c80096 | 69 | void start (); |
okini3939 | 6:9e7b4eeac6ec | 70 | /** Stop DMX send operation |
okini3939 | 4:dd0544c80096 | 71 | */ |
okini3939 | 4:dd0544c80096 | 72 | void stop (); |
okini3939 | 3:2eb66b4d99bd | 73 | |
okini3939 | 0:cbff6bf41542 | 74 | volatile int is_recived, is_sent; |
okini3939 | 0:cbff6bf41542 | 75 | |
okini3939 | 0:cbff6bf41542 | 76 | protected: |
okini3939 | 0:cbff6bf41542 | 77 | |
okini3939 | 0:cbff6bf41542 | 78 | void int_timer (); |
okini3939 | 0:cbff6bf41542 | 79 | void int_tx (); |
okini3939 | 0:cbff6bf41542 | 80 | void int_rx (); |
okini3939 | 0:cbff6bf41542 | 81 | |
okini3939 | 5:72039cd4c874 | 82 | Serial _dmx; |
okini3939 | 0:cbff6bf41542 | 83 | Timeout timeout01; |
okini3939 | 6:9e7b4eeac6ec | 84 | volatile DMX_MODE mode_tx, mode_rx; |
okini3939 | 6:9e7b4eeac6ec | 85 | volatile int addr_tx, addr_rx; |
okini3939 | 6:9e7b4eeac6ec | 86 | unsigned char data_tx[DMX_SIZE]; |
okini3939 | 6:9e7b4eeac6ec | 87 | unsigned char data_rx[DMX_SIZE]; |
okini3939 | 6:9e7b4eeac6ec | 88 | |
okini3939 | 6:9e7b4eeac6ec | 89 | private: |
okini3939 | 5:72039cd4c874 | 90 | #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) |
okini3939 | 0:cbff6bf41542 | 91 | __IO uint8_t *uart_lcr; |
okini3939 | 0:cbff6bf41542 | 92 | __I uint8_t *uart_lsr; |
okini3939 | 0:cbff6bf41542 | 93 | __IO uint8_t *uart_thr; |
okini3939 | 0:cbff6bf41542 | 94 | __I uint8_t *uart_rbr; |
okini3939 | 5:72039cd4c874 | 95 | #elif defined(TARGET_LPC11U24) |
okini3939 | 5:72039cd4c874 | 96 | __IO uint32_t *uart_lcr; |
okini3939 | 5:72039cd4c874 | 97 | __I uint32_t *uart_lsr; |
okini3939 | 5:72039cd4c874 | 98 | __IO uint32_t *uart_thr; |
okini3939 | 5:72039cd4c874 | 99 | __I uint32_t *uart_rbr; |
okini3939 | 5:72039cd4c874 | 100 | #endif |
okini3939 | 0:cbff6bf41542 | 101 | |
okini3939 | 0:cbff6bf41542 | 102 | }; |
okini3939 | 0:cbff6bf41542 | 103 | |
okini3939 | 0:cbff6bf41542 | 104 | #endif |