need to use Dynamixel
Dependents: YOZAKURA_ARM YOZAKURA_ARM_USB YOZAKURA_ARM_USB_Keyboard YOZAKURA_ARM_Keyboard0424 ... more
Fork of SerialHalfDuplex by
SerialHalfDuplex.cpp@2:5ecc72a47df0, 2014-04-01 (annotated)
- Committer:
- aimen
- Date:
- Tue Apr 01 06:50:02 2014 +0000
- Revision:
- 2:5ecc72a47df0
- Parent:
- 1:8fd1fa67565e
- Child:
- 3:8eeadefbee4e
no change
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aimen | 2:5ecc72a47df0 | 1 | /* mbed Microcontroller Library |
GIPetrou | 1:8fd1fa67565e | 2 | * Copyright (c) 2006-2012 ARM Limited |
GIPetrou | 1:8fd1fa67565e | 3 | * |
GIPetrou | 1:8fd1fa67565e | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
GIPetrou | 1:8fd1fa67565e | 5 | * of this software and associated documentation files (the "Software"), to deal |
GIPetrou | 1:8fd1fa67565e | 6 | * in the Software without restriction, including without limitation the rights |
GIPetrou | 1:8fd1fa67565e | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
GIPetrou | 1:8fd1fa67565e | 8 | * copies of the Software, and to permit persons to whom the Software is |
GIPetrou | 1:8fd1fa67565e | 9 | * furnished to do so, subject to the following conditions: |
GIPetrou | 1:8fd1fa67565e | 10 | * |
GIPetrou | 1:8fd1fa67565e | 11 | * The above copyright notice and this permission notice shall be included in |
GIPetrou | 1:8fd1fa67565e | 12 | * all copies or substantial portions of the Software. |
GIPetrou | 1:8fd1fa67565e | 13 | * |
GIPetrou | 1:8fd1fa67565e | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
GIPetrou | 1:8fd1fa67565e | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
GIPetrou | 1:8fd1fa67565e | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
GIPetrou | 1:8fd1fa67565e | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
GIPetrou | 1:8fd1fa67565e | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
GIPetrou | 1:8fd1fa67565e | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
GIPetrou | 1:8fd1fa67565e | 20 | * SOFTWARE. |
GIPetrou | 1:8fd1fa67565e | 21 | * |
GIPetrou | 1:8fd1fa67565e | 22 | * NOTE: This is an unsupported legacy untested library. |
GIPetrou | 1:8fd1fa67565e | 23 | */ |
GIPetrou | 1:8fd1fa67565e | 24 | #include "SerialHalfDuplex.h" |
aimen | 2:5ecc72a47df0 | 25 | |
GIPetrou | 1:8fd1fa67565e | 26 | #if DEVICE_SERIAL |
aimen | 2:5ecc72a47df0 | 27 | |
GIPetrou | 1:8fd1fa67565e | 28 | #include "pinmap.h" |
GIPetrou | 1:8fd1fa67565e | 29 | #include "serial_api.h" |
GIPetrou | 1:8fd1fa67565e | 30 | #include "gpio_api.h" |
aimen | 2:5ecc72a47df0 | 31 | |
GIPetrou | 1:8fd1fa67565e | 32 | namespace mbed { |
aimen | 2:5ecc72a47df0 | 33 | |
GIPetrou | 1:8fd1fa67565e | 34 | SerialHalfDuplex::SerialHalfDuplex(PinName tx, PinName rx, const char *name) |
GIPetrou | 1:8fd1fa67565e | 35 | : Serial(tx, rx, name) { |
GIPetrou | 1:8fd1fa67565e | 36 | _txpin = tx; |
GIPetrou | 1:8fd1fa67565e | 37 | |
aimen | 2:5ecc72a47df0 | 38 | // set as input |
GIPetrou | 1:8fd1fa67565e | 39 | gpio_set(_txpin); |
GIPetrou | 1:8fd1fa67565e | 40 | pin_mode(_txpin, PullNone); // no pull |
GIPetrou | 1:8fd1fa67565e | 41 | pin_function(_txpin, 0); // set as gpio |
GIPetrou | 1:8fd1fa67565e | 42 | } |
aimen | 2:5ecc72a47df0 | 43 | |
GIPetrou | 1:8fd1fa67565e | 44 | // To transmit a byte in half duplex mode: |
GIPetrou | 1:8fd1fa67565e | 45 | // 1. Disable interrupts, so we don't trigger on loopback byte |
GIPetrou | 1:8fd1fa67565e | 46 | // 2. Set tx pin to UART out |
GIPetrou | 1:8fd1fa67565e | 47 | // 3. Transmit byte as normal |
GIPetrou | 1:8fd1fa67565e | 48 | // 4. Read back byte from looped back tx pin - this both confirms that the |
GIPetrou | 1:8fd1fa67565e | 49 | // transmit has occurred, and also clears the byte from the buffer. |
GIPetrou | 1:8fd1fa67565e | 50 | // 5. Return pin to input mode |
GIPetrou | 1:8fd1fa67565e | 51 | // 6. Re-enable interrupts |
aimen | 2:5ecc72a47df0 | 52 | |
GIPetrou | 1:8fd1fa67565e | 53 | int SerialHalfDuplex::_putc(int c) { |
GIPetrou | 1:8fd1fa67565e | 54 | int retc; |
GIPetrou | 1:8fd1fa67565e | 55 | |
GIPetrou | 1:8fd1fa67565e | 56 | // TODO: We should not disable all interrupts |
GIPetrou | 1:8fd1fa67565e | 57 | __disable_irq(); |
GIPetrou | 1:8fd1fa67565e | 58 | |
GIPetrou | 1:8fd1fa67565e | 59 | serial_pinout_tx(_txpin); |
GIPetrou | 1:8fd1fa67565e | 60 | |
GIPetrou | 1:8fd1fa67565e | 61 | Serial::_putc(c); |
GIPetrou | 1:8fd1fa67565e | 62 | retc = Serial::getc(); // reading also clears any interrupt |
GIPetrou | 1:8fd1fa67565e | 63 | |
GIPetrou | 1:8fd1fa67565e | 64 | pin_function(_txpin, 0); |
GIPetrou | 1:8fd1fa67565e | 65 | |
GIPetrou | 1:8fd1fa67565e | 66 | __enable_irq(); |
GIPetrou | 1:8fd1fa67565e | 67 | |
GIPetrou | 1:8fd1fa67565e | 68 | return retc; |
GIPetrou | 1:8fd1fa67565e | 69 | } |
aimen | 2:5ecc72a47df0 | 70 | |
GIPetrou | 1:8fd1fa67565e | 71 | int SerialHalfDuplex::_getc(void) { |
GIPetrou | 1:8fd1fa67565e | 72 | return Serial::_getc(); |
GIPetrou | 1:8fd1fa67565e | 73 | } |
aimen | 2:5ecc72a47df0 | 74 | |
GIPetrou | 1:8fd1fa67565e | 75 | } // End namespace |
aimen | 2:5ecc72a47df0 | 76 | |
aimen | 2:5ecc72a47df0 | 77 | #endif |