Colin Hogben / micropython

Dependents:   micropython-repl

Committer:
Colin Hogben
Date:
Sun Apr 17 23:08:33 2016 +0100
Revision:
3:d8dfbbbd0fc9
Parent:
0:5868e8752d44
Child:
6:3e98ebcedb4c
modmbed: add Serial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pythontech 0:5868e8752d44 1 /*
pythontech 0:5868e8752d44 2 * The MIT License (MIT)
pythontech 0:5868e8752d44 3 *
pythontech 0:5868e8752d44 4 * Copyright (c) 2016 Colin Hogben
pythontech 0:5868e8752d44 5 *
pythontech 0:5868e8752d44 6 * Permission is hereby granted, free of charge, to any person obtaining a copy
pythontech 0:5868e8752d44 7 * of this software and associated documentation files (the "Software"), to deal
pythontech 0:5868e8752d44 8 * in the Software without restriction, including without limitation the rights
pythontech 0:5868e8752d44 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
pythontech 0:5868e8752d44 10 * copies of the Software, and to permit persons to whom the Software is
pythontech 0:5868e8752d44 11 * furnished to do so, subject to the following conditions:
pythontech 0:5868e8752d44 12 *
pythontech 0:5868e8752d44 13 * The above copyright notice and this permission notice shall be included in
pythontech 0:5868e8752d44 14 * all copies or substantial portions of the Software.
pythontech 0:5868e8752d44 15 *
pythontech 0:5868e8752d44 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
pythontech 0:5868e8752d44 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
pythontech 0:5868e8752d44 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
pythontech 0:5868e8752d44 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
pythontech 0:5868e8752d44 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
pythontech 0:5868e8752d44 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
pythontech 0:5868e8752d44 22 * THE SOFTWARE.
pythontech 0:5868e8752d44 23 */
pythontech 0:5868e8752d44 24
pythontech 0:5868e8752d44 25 /**
pythontech 0:5868e8752d44 26 * Shims to isolate the pure C world of micropython from the C++ world
pythontech 0:5868e8752d44 27 * of mbed high-level objects. Maybe there's a way to write the module
pythontech 0:5868e8752d44 28 * directly in a compatible way but my C++-fu is not that strong.
pythontech 0:5868e8752d44 29 */
pythontech 0:5868e8752d44 30 extern "C" {
pythontech 0:5868e8752d44 31 #include "py/mpconfig.h"
pythontech 0:5868e8752d44 32 }
pythontech 0:5868e8752d44 33
pythontech 0:5868e8752d44 34 #if MICROPY_PY_MBED
pythontech 0:5868e8752d44 35
pythontech 0:5868e8752d44 36 #include "mbed.h"
pythontech 0:5868e8752d44 37 extern "C" {
pythontech 0:5868e8752d44 38 #include "modmbed_i.h"
pythontech 0:5868e8752d44 39 }
pythontech 0:5868e8752d44 40
pythontech 0:5868e8752d44 41 void *mbed_DigitalOut__create(int pin)
pythontech 0:5868e8752d44 42 {
pythontech 0:5868e8752d44 43 DigitalOut *dout = new DigitalOut((PinName)pin);
pythontech 0:5868e8752d44 44 return (void *)dout;
pythontech 0:5868e8752d44 45 }
pythontech 0:5868e8752d44 46
pythontech 0:5868e8752d44 47 void mbed_DigitalOut__write(void *self, int value)
pythontech 0:5868e8752d44 48 {
pythontech 0:5868e8752d44 49 DigitalOut *dout = (DigitalOut *)self;
pythontech 0:5868e8752d44 50 *dout = value;
pythontech 0:5868e8752d44 51 }
pythontech 0:5868e8752d44 52
Colin Hogben 3:d8dfbbbd0fc9 53 void *mbed_Serial__create(int tx, int rx)
Colin Hogben 3:d8dfbbbd0fc9 54 {
Colin Hogben 3:d8dfbbbd0fc9 55 Serial *serial = new Serial((PinName)tx, (PinName)rx);
Colin Hogben 3:d8dfbbbd0fc9 56 return (void *)serial;
Colin Hogben 3:d8dfbbbd0fc9 57 }
Colin Hogben 3:d8dfbbbd0fc9 58
Colin Hogben 3:d8dfbbbd0fc9 59 void mbed_Serial__putc(void *self, int c)
Colin Hogben 3:d8dfbbbd0fc9 60 {
Colin Hogben 3:d8dfbbbd0fc9 61 Serial *serial = (Serial *)self;
Colin Hogben 3:d8dfbbbd0fc9 62 serial->putc(c);
Colin Hogben 3:d8dfbbbd0fc9 63 }
Colin Hogben 3:d8dfbbbd0fc9 64
Colin Hogben 3:d8dfbbbd0fc9 65 void mbed_Serial__puts(void *self, const char *str)
Colin Hogben 3:d8dfbbbd0fc9 66 {
Colin Hogben 3:d8dfbbbd0fc9 67 Serial *serial = (Serial *)self;
Colin Hogben 3:d8dfbbbd0fc9 68 serial->puts(str);
Colin Hogben 3:d8dfbbbd0fc9 69 }
Colin Hogben 3:d8dfbbbd0fc9 70
Colin Hogben 3:d8dfbbbd0fc9 71 int mbed_Serial__getc(void *self)
Colin Hogben 3:d8dfbbbd0fc9 72 {
Colin Hogben 3:d8dfbbbd0fc9 73 Serial *serial = (Serial *)self;
Colin Hogben 3:d8dfbbbd0fc9 74 return serial->getc();
Colin Hogben 3:d8dfbbbd0fc9 75 }
Colin Hogben 3:d8dfbbbd0fc9 76
pythontech 0:5868e8752d44 77 #endif