DMX library
Fork of DMX by
DMX.h@15:4ea4a31c7609, 2014-08-26 (annotated)
- Committer:
- okini3939
- Date:
- Tue Aug 26 13:25:24 2014 +0000
- Revision:
- 15:4ea4a31c7609
- Parent:
- 14:cef8749fd54d
- Child:
- 16:822dc27bc720
fix short slots.; change to 200us from 10us between time.
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 | 14:cef8749fd54d | 15 | #include "RawSerial.h" |
okini3939 | 0:cbff6bf41542 | 16 | |
okini3939 | 1:f0d988e15810 | 17 | #define DMX_UART_DIRECT |
okini3939 | 0:cbff6bf41542 | 18 | |
okini3939 | 0:cbff6bf41542 | 19 | #define DMX_SIZE 512 |
okini3939 | 9:e687f321c428 | 20 | #define DMX_TIME_BREAK 100 // 100us (88us-1s) |
okini3939 | 9:e687f321c428 | 21 | #define DMX_TIME_MAB 10 // 10us (8us-1s) |
okini3939 | 15:4ea4a31c7609 | 22 | #define DMX_TIME_BETWEEN 200 // 10us (0-1s) |
okini3939 | 9:e687f321c428 | 23 | #define DMX_START_CODE 0 |
okini3939 | 0:cbff6bf41542 | 24 | |
okini3939 | 0:cbff6bf41542 | 25 | enum DMX_MODE { |
okini3939 | 0:cbff6bf41542 | 26 | DMX_MODE_BEGIN, |
okini3939 | 0:cbff6bf41542 | 27 | DMX_MODE_START, |
okini3939 | 0:cbff6bf41542 | 28 | DMX_MODE_BREAK, |
okini3939 | 0:cbff6bf41542 | 29 | DMX_MODE_MAB, |
okini3939 | 0:cbff6bf41542 | 30 | DMX_MODE_DATA, |
okini3939 | 0:cbff6bf41542 | 31 | DMX_MODE_ERROR, |
okini3939 | 4:dd0544c80096 | 32 | DMX_MODE_STOP, |
okini3939 | 0:cbff6bf41542 | 33 | }; |
okini3939 | 0:cbff6bf41542 | 34 | |
okini3939 | 0:cbff6bf41542 | 35 | /** DMX512 class (sender/client) |
okini3939 | 0:cbff6bf41542 | 36 | */ |
okini3939 | 0:cbff6bf41542 | 37 | class DMX { |
okini3939 | 0:cbff6bf41542 | 38 | public: |
okini3939 | 0:cbff6bf41542 | 39 | /** init DMX class |
okini3939 | 0:cbff6bf41542 | 40 | * @param p_tx TX serial port (p9, p13, p28) |
okini3939 | 0:cbff6bf41542 | 41 | * @param p_rx RX serial port (p10, p14, p27) |
okini3939 | 0:cbff6bf41542 | 42 | */ |
okini3939 | 0:cbff6bf41542 | 43 | DMX (PinName p_tx, PinName p_rx); |
okini3939 | 0:cbff6bf41542 | 44 | |
okini3939 | 6:9e7b4eeac6ec | 45 | /** Send the data |
okini3939 | 6:9e7b4eeac6ec | 46 | * @param addr DMX data address (0-511) |
okini3939 | 0:cbff6bf41542 | 47 | * @param data DMX data (0-255) |
okini3939 | 0:cbff6bf41542 | 48 | */ |
okini3939 | 6:9e7b4eeac6ec | 49 | void put (int addr, int data); |
okini3939 | 6:9e7b4eeac6ec | 50 | /** Send the data |
okini3939 | 6:9e7b4eeac6ec | 51 | * @param buf DMX data buffer |
okini3939 | 6:9e7b4eeac6ec | 52 | * @param addr DMX data address |
okini3939 | 6:9e7b4eeac6ec | 53 | * @param len data length |
okini3939 | 6:9e7b4eeac6ec | 54 | */ |
okini3939 | 6:9e7b4eeac6ec | 55 | void put (unsigned char *buf, int addr = 0, int len = DMX_SIZE); |
okini3939 | 0:cbff6bf41542 | 56 | |
okini3939 | 6:9e7b4eeac6ec | 57 | /** Send the data |
okini3939 | 7:16d6874076dd | 58 | * @param addr DMX data address (0-511) |
okini3939 | 0:cbff6bf41542 | 59 | * @return DMX data (0-255) |
okini3939 | 0:cbff6bf41542 | 60 | */ |
okini3939 | 6:9e7b4eeac6ec | 61 | int get (int addr); |
okini3939 | 6:9e7b4eeac6ec | 62 | /** Send the data |
okini3939 | 6:9e7b4eeac6ec | 63 | * @param buf DMX data buffer |
okini3939 | 6:9e7b4eeac6ec | 64 | * @param addr DMX data address |
okini3939 | 6:9e7b4eeac6ec | 65 | * @param len data length |
okini3939 | 6:9e7b4eeac6ec | 66 | */ |
okini3939 | 6:9e7b4eeac6ec | 67 | void get (unsigned char *buf, int addr = 0, int len = DMX_SIZE); |
okini3939 | 0:cbff6bf41542 | 68 | |
okini3939 | 6:9e7b4eeac6ec | 69 | /** Start DMX send operation |
okini3939 | 4:dd0544c80096 | 70 | */ |
okini3939 | 4:dd0544c80096 | 71 | void start (); |
okini3939 | 6:9e7b4eeac6ec | 72 | /** Stop DMX send operation |
okini3939 | 4:dd0544c80096 | 73 | */ |
okini3939 | 4:dd0544c80096 | 74 | void stop (); |
okini3939 | 12:1f176eee2d28 | 75 | /** Clear DMX data |
okini3939 | 12:1f176eee2d28 | 76 | */ |
okini3939 | 12:1f176eee2d28 | 77 | void clear (); |
okini3939 | 3:2eb66b4d99bd | 78 | |
okini3939 | 0:cbff6bf41542 | 79 | volatile int is_recived, is_sent; |
okini3939 | 0:cbff6bf41542 | 80 | |
okini3939 | 0:cbff6bf41542 | 81 | protected: |
okini3939 | 0:cbff6bf41542 | 82 | |
okini3939 | 0:cbff6bf41542 | 83 | void int_timer (); |
okini3939 | 0:cbff6bf41542 | 84 | void int_tx (); |
okini3939 | 0:cbff6bf41542 | 85 | void int_rx (); |
okini3939 | 0:cbff6bf41542 | 86 | |
okini3939 | 14:cef8749fd54d | 87 | // Serial _dmx; |
okini3939 | 13:9841af9ac344 | 88 | RawSerial _dmx; |
okini3939 | 0:cbff6bf41542 | 89 | Timeout timeout01; |
okini3939 | 6:9e7b4eeac6ec | 90 | volatile DMX_MODE mode_tx, mode_rx; |
okini3939 | 6:9e7b4eeac6ec | 91 | volatile int addr_tx, addr_rx; |
okini3939 | 6:9e7b4eeac6ec | 92 | unsigned char data_tx[DMX_SIZE]; |
okini3939 | 6:9e7b4eeac6ec | 93 | unsigned char data_rx[DMX_SIZE]; |
okini3939 | 6:9e7b4eeac6ec | 94 | |
okini3939 | 6:9e7b4eeac6ec | 95 | private: |
okini3939 | 13:9841af9ac344 | 96 | #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC4088) |
okini3939 | 8:d4a45bba41d2 | 97 | LPC_UART_TypeDef *_uart; |
okini3939 | 15:4ea4a31c7609 | 98 | #elif defined(TARGET_LPC11UXX) |
okini3939 | 8:d4a45bba41d2 | 99 | LPC_USART_Type *_uart; |
stanly88 | 10:b748aab8404c | 100 | #elif defined(TARGET_LPC11XX) |
stanly88 | 10:b748aab8404c | 101 | LPC_UART_TypeDef *_uart; |
okini3939 | 13:9841af9ac344 | 102 | #else |
okini3939 | 13:9841af9ac344 | 103 | #error "this CPU not supported." |
okini3939 | 5:72039cd4c874 | 104 | #endif |
okini3939 | 0:cbff6bf41542 | 105 | |
okini3939 | 0:cbff6bf41542 | 106 | }; |
okini3939 | 0:cbff6bf41542 | 107 | |
okini3939 | 0:cbff6bf41542 | 108 | #endif |