DMX library
Fork of DMX by
DMX.h@9:e687f321c428, 2013-03-29 (annotated)
- Committer:
- okini3939
- Date:
- Fri Mar 29 02:06:50 2013 +0000
- Revision:
- 9:e687f321c428
- Parent:
- 8:d4a45bba41d2
- Child:
- 10:b748aab8404c
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 | 9:e687f321c428 | 19 | #define DMX_TIME_BREAK 100 // 100us (88us-1s) |
okini3939 | 9:e687f321c428 | 20 | #define DMX_TIME_MAB 10 // 10us (8us-1s) |
okini3939 | 9:e687f321c428 | 21 | #define DMX_TIME_BETWEEN 10 // 10us (0-1s) |
okini3939 | 9:e687f321c428 | 22 | #define DMX_START_CODE 0 |
okini3939 | 0:cbff6bf41542 | 23 | |
okini3939 | 0:cbff6bf41542 | 24 | enum DMX_MODE { |
okini3939 | 0:cbff6bf41542 | 25 | DMX_MODE_BEGIN, |
okini3939 | 0:cbff6bf41542 | 26 | DMX_MODE_START, |
okini3939 | 0:cbff6bf41542 | 27 | DMX_MODE_BREAK, |
okini3939 | 0:cbff6bf41542 | 28 | DMX_MODE_MAB, |
okini3939 | 0:cbff6bf41542 | 29 | DMX_MODE_DATA, |
okini3939 | 0:cbff6bf41542 | 30 | DMX_MODE_ERROR, |
okini3939 | 4:dd0544c80096 | 31 | DMX_MODE_STOP, |
okini3939 | 0:cbff6bf41542 | 32 | }; |
okini3939 | 0:cbff6bf41542 | 33 | |
okini3939 | 0:cbff6bf41542 | 34 | /** DMX512 class (sender/client) |
okini3939 | 0:cbff6bf41542 | 35 | */ |
okini3939 | 0:cbff6bf41542 | 36 | class DMX { |
okini3939 | 0:cbff6bf41542 | 37 | public: |
okini3939 | 0:cbff6bf41542 | 38 | /** init DMX class |
okini3939 | 0:cbff6bf41542 | 39 | * @param p_tx TX serial port (p9, p13, p28) |
okini3939 | 0:cbff6bf41542 | 40 | * @param p_rx RX serial port (p10, p14, p27) |
okini3939 | 0:cbff6bf41542 | 41 | */ |
okini3939 | 0:cbff6bf41542 | 42 | DMX (PinName p_tx, PinName p_rx); |
okini3939 | 0:cbff6bf41542 | 43 | |
okini3939 | 6:9e7b4eeac6ec | 44 | /** Send the data |
okini3939 | 6:9e7b4eeac6ec | 45 | * @param addr DMX data address (0-511) |
okini3939 | 0:cbff6bf41542 | 46 | * @param data DMX data (0-255) |
okini3939 | 0:cbff6bf41542 | 47 | */ |
okini3939 | 6:9e7b4eeac6ec | 48 | void put (int addr, int data); |
okini3939 | 6:9e7b4eeac6ec | 49 | /** Send the data |
okini3939 | 6:9e7b4eeac6ec | 50 | * @param buf DMX data buffer |
okini3939 | 6:9e7b4eeac6ec | 51 | * @param addr DMX data address |
okini3939 | 6:9e7b4eeac6ec | 52 | * @param len data length |
okini3939 | 6:9e7b4eeac6ec | 53 | */ |
okini3939 | 6:9e7b4eeac6ec | 54 | void put (unsigned char *buf, int addr = 0, int len = DMX_SIZE); |
okini3939 | 0:cbff6bf41542 | 55 | |
okini3939 | 6:9e7b4eeac6ec | 56 | /** Send the data |
okini3939 | 7:16d6874076dd | 57 | * @param addr DMX data address (0-511) |
okini3939 | 0:cbff6bf41542 | 58 | * @return DMX data (0-255) |
okini3939 | 0:cbff6bf41542 | 59 | */ |
okini3939 | 6:9e7b4eeac6ec | 60 | int get (int addr); |
okini3939 | 6:9e7b4eeac6ec | 61 | /** Send the data |
okini3939 | 6:9e7b4eeac6ec | 62 | * @param buf DMX data buffer |
okini3939 | 6:9e7b4eeac6ec | 63 | * @param addr DMX data address |
okini3939 | 6:9e7b4eeac6ec | 64 | * @param len data length |
okini3939 | 6:9e7b4eeac6ec | 65 | */ |
okini3939 | 6:9e7b4eeac6ec | 66 | void get (unsigned char *buf, int addr = 0, int len = DMX_SIZE); |
okini3939 | 0:cbff6bf41542 | 67 | |
okini3939 | 6:9e7b4eeac6ec | 68 | /** Start DMX send operation |
okini3939 | 4:dd0544c80096 | 69 | */ |
okini3939 | 4:dd0544c80096 | 70 | void start (); |
okini3939 | 6:9e7b4eeac6ec | 71 | /** Stop DMX send operation |
okini3939 | 4:dd0544c80096 | 72 | */ |
okini3939 | 4:dd0544c80096 | 73 | void stop (); |
okini3939 | 3:2eb66b4d99bd | 74 | |
okini3939 | 0:cbff6bf41542 | 75 | volatile int is_recived, is_sent; |
okini3939 | 0:cbff6bf41542 | 76 | |
okini3939 | 0:cbff6bf41542 | 77 | protected: |
okini3939 | 0:cbff6bf41542 | 78 | |
okini3939 | 0:cbff6bf41542 | 79 | void int_timer (); |
okini3939 | 0:cbff6bf41542 | 80 | void int_tx (); |
okini3939 | 0:cbff6bf41542 | 81 | void int_rx (); |
okini3939 | 0:cbff6bf41542 | 82 | |
okini3939 | 5:72039cd4c874 | 83 | Serial _dmx; |
okini3939 | 0:cbff6bf41542 | 84 | Timeout timeout01; |
okini3939 | 6:9e7b4eeac6ec | 85 | volatile DMX_MODE mode_tx, mode_rx; |
okini3939 | 6:9e7b4eeac6ec | 86 | volatile int addr_tx, addr_rx; |
okini3939 | 6:9e7b4eeac6ec | 87 | unsigned char data_tx[DMX_SIZE]; |
okini3939 | 6:9e7b4eeac6ec | 88 | unsigned char data_rx[DMX_SIZE]; |
okini3939 | 6:9e7b4eeac6ec | 89 | |
okini3939 | 6:9e7b4eeac6ec | 90 | private: |
okini3939 | 5:72039cd4c874 | 91 | #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) |
okini3939 | 8:d4a45bba41d2 | 92 | LPC_UART_TypeDef *_uart; |
okini3939 | 5:72039cd4c874 | 93 | #elif defined(TARGET_LPC11U24) |
okini3939 | 8:d4a45bba41d2 | 94 | LPC_USART_Type *_uart; |
okini3939 | 5:72039cd4c874 | 95 | #endif |
okini3939 | 0:cbff6bf41542 | 96 | |
okini3939 | 0:cbff6bf41542 | 97 | }; |
okini3939 | 0:cbff6bf41542 | 98 | |
okini3939 | 0:cbff6bf41542 | 99 | #endif |