Futaba S-BUS Library. Let you control 16 servos and 2 digital channels

Dependencies:   mbed

Committer:
Digixx
Date:
Wed Mar 07 18:18:43 2012 +0000
Revision:
0:83e415034198

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Digixx 0:83e415034198 1 /*
Digixx 0:83e415034198 2 Copyright (c) 2010 Andy Kirkham
Digixx 0:83e415034198 3
Digixx 0:83e415034198 4 Permission is hereby granted, free of charge, to any person obtaining a copy
Digixx 0:83e415034198 5 of this software and associated documentation files (the "Software"), to deal
Digixx 0:83e415034198 6 in the Software without restriction, including without limitation the rights
Digixx 0:83e415034198 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Digixx 0:83e415034198 8 copies of the Software, and to permit persons to whom the Software is
Digixx 0:83e415034198 9 furnished to do so, subject to the following conditions:
Digixx 0:83e415034198 10
Digixx 0:83e415034198 11 The above copyright notice and this permission notice shall be included in
Digixx 0:83e415034198 12 all copies or substantial portions of the Software.
Digixx 0:83e415034198 13
Digixx 0:83e415034198 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Digixx 0:83e415034198 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Digixx 0:83e415034198 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Digixx 0:83e415034198 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Digixx 0:83e415034198 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Digixx 0:83e415034198 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Digixx 0:83e415034198 20 THE SOFTWARE.
Digixx 0:83e415034198 21 */
Digixx 0:83e415034198 22
Digixx 0:83e415034198 23 #include "MODSERIAL.h"
Digixx 0:83e415034198 24 #include "MACROS.h"
Digixx 0:83e415034198 25
Digixx 0:83e415034198 26 namespace AjK {
Digixx 0:83e415034198 27
Digixx 0:83e415034198 28 void
Digixx 0:83e415034198 29 MODSERIAL::init(int txSize, int rxSize)
Digixx 0:83e415034198 30 {
Digixx 0:83e415034198 31 disableIrq();
Digixx 0:83e415034198 32
Digixx 0:83e415034198 33 callbackInfo.setSerial(this);
Digixx 0:83e415034198 34
Digixx 0:83e415034198 35 switch(_uidx) {
Digixx 0:83e415034198 36 case 0: _base = LPC_UART0; break;
Digixx 0:83e415034198 37 case 1: _base = LPC_UART1; break;
Digixx 0:83e415034198 38 case 2: _base = LPC_UART2; break;
Digixx 0:83e415034198 39 case 3: _base = LPC_UART3; break;
Digixx 0:83e415034198 40 default : _base = NULL; break;
Digixx 0:83e415034198 41 }
Digixx 0:83e415034198 42
Digixx 0:83e415034198 43 dmaSendChannel = -1;
Digixx 0:83e415034198 44 moddma_p = (void *)NULL;
Digixx 0:83e415034198 45
Digixx 0:83e415034198 46 if (_base != NULL) {
Digixx 0:83e415034198 47 buffer_size[RxIrq] = rxSize;
Digixx 0:83e415034198 48 buffer[RxIrq] = rxSize > 0 ? (char *)malloc(buffer_size[RxIrq]) : (char *)NULL;
Digixx 0:83e415034198 49 buffer_in[RxIrq] = 0;
Digixx 0:83e415034198 50 buffer_out[RxIrq] = 0;
Digixx 0:83e415034198 51 buffer_count[RxIrq] = 0;
Digixx 0:83e415034198 52 buffer_overflow[RxIrq] = 0;
Digixx 0:83e415034198 53 Serial::attach(this, &MODSERIAL::isr_rx, Serial::RxIrq);
Digixx 0:83e415034198 54
Digixx 0:83e415034198 55 buffer_size[TxIrq] = txSize;
Digixx 0:83e415034198 56 buffer[TxIrq] = txSize > 0 ? (char *)malloc(buffer_size[TxIrq]) : (char *)NULL;
Digixx 0:83e415034198 57 buffer_in[TxIrq] = 0;
Digixx 0:83e415034198 58 buffer_out[TxIrq] = 0;
Digixx 0:83e415034198 59 buffer_count[TxIrq] = 0;
Digixx 0:83e415034198 60 buffer_overflow[TxIrq] = 0;
Digixx 0:83e415034198 61 Serial::attach(this, &MODSERIAL::isr_tx, Serial::TxIrq);
Digixx 0:83e415034198 62 }
Digixx 0:83e415034198 63 else {
Digixx 0:83e415034198 64 error("MODSERIAL must have a defined UART to function.");
Digixx 0:83e415034198 65 }
Digixx 0:83e415034198 66
Digixx 0:83e415034198 67 _FCR = MODSERIAL_FIFO_ENABLE | MODSERIAL_FIFO_RX_RESET | MODSERIAL_FIFO_TX_RESET;
Digixx 0:83e415034198 68
Digixx 0:83e415034198 69 auto_detect_char = 0;
Digixx 0:83e415034198 70
Digixx 0:83e415034198 71 enableIrq();
Digixx 0:83e415034198 72 }
Digixx 0:83e415034198 73
Digixx 0:83e415034198 74 }; // namespace AjK ends