Blink, remove compiler errors

Dependents:   STM32F031_Blink_Aug17

Fork of mbed-STM32F030F4 by Nothing Special

Committer:
stupidcode
Date:
Sun Aug 27 18:32:02 2017 +0000
Revision:
12:ee1efe6181e7
Parent:
0:38ccae254a29
Blink;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mega64 0:38ccae254a29 1 /* mbed Microcontroller Library
mega64 0:38ccae254a29 2 * Copyright (c) 2006-2013 ARM Limited
mega64 0:38ccae254a29 3 *
mega64 0:38ccae254a29 4 * Licensed under the Apache License, Version 2.0 (the "License");
mega64 0:38ccae254a29 5 * you may not use this file except in compliance with the License.
mega64 0:38ccae254a29 6 * You may obtain a copy of the License at
mega64 0:38ccae254a29 7 *
mega64 0:38ccae254a29 8 * http://www.apache.org/licenses/LICENSE-2.0
mega64 0:38ccae254a29 9 *
mega64 0:38ccae254a29 10 * Unless required by applicable law or agreed to in writing, software
mega64 0:38ccae254a29 11 * distributed under the License is distributed on an "AS IS" BASIS,
mega64 0:38ccae254a29 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mega64 0:38ccae254a29 13 * See the License for the specific language governing permissions and
mega64 0:38ccae254a29 14 * limitations under the License.
mega64 0:38ccae254a29 15 */
mega64 0:38ccae254a29 16 #include "SerialBase.h"
mega64 0:38ccae254a29 17 #include "wait_api.h"
mega64 0:38ccae254a29 18
mega64 0:38ccae254a29 19 #if DEVICE_SERIAL
mega64 0:38ccae254a29 20
mega64 0:38ccae254a29 21 namespace mbed {
mega64 0:38ccae254a29 22
mega64 0:38ccae254a29 23 SerialBase::SerialBase(PinName tx, PinName rx) : _serial(), _baud(9600) {
mega64 0:38ccae254a29 24 serial_init(&_serial, tx, rx);
mega64 0:38ccae254a29 25 serial_irq_handler(&_serial, SerialBase::_irq_handler, (uint32_t)this);
mega64 0:38ccae254a29 26 }
mega64 0:38ccae254a29 27
mega64 0:38ccae254a29 28 void SerialBase::baud(int baudrate) {
mega64 0:38ccae254a29 29 serial_baud(&_serial, baudrate);
mega64 0:38ccae254a29 30 _baud = baudrate;
mega64 0:38ccae254a29 31 }
mega64 0:38ccae254a29 32
mega64 0:38ccae254a29 33 void SerialBase::format(int bits, Parity parity, int stop_bits) {
mega64 0:38ccae254a29 34 serial_format(&_serial, bits, (SerialParity)parity, stop_bits);
mega64 0:38ccae254a29 35 }
mega64 0:38ccae254a29 36
mega64 0:38ccae254a29 37 int SerialBase::readable() {
mega64 0:38ccae254a29 38 return serial_readable(&_serial);
mega64 0:38ccae254a29 39 }
mega64 0:38ccae254a29 40
mega64 0:38ccae254a29 41
mega64 0:38ccae254a29 42 int SerialBase::writeable() {
mega64 0:38ccae254a29 43 return serial_writable(&_serial);
mega64 0:38ccae254a29 44 }
mega64 0:38ccae254a29 45
mega64 0:38ccae254a29 46 void SerialBase::attach(void (*fptr)(void), IrqType type) {
mega64 0:38ccae254a29 47 if (fptr) {
mega64 0:38ccae254a29 48 _irq[type].attach(fptr);
mega64 0:38ccae254a29 49 serial_irq_set(&_serial, (SerialIrq)type, 1);
mega64 0:38ccae254a29 50 } else {
mega64 0:38ccae254a29 51 serial_irq_set(&_serial, (SerialIrq)type, 0);
mega64 0:38ccae254a29 52 }
mega64 0:38ccae254a29 53 }
mega64 0:38ccae254a29 54
mega64 0:38ccae254a29 55 void SerialBase::_irq_handler(uint32_t id, SerialIrq irq_type) {
mega64 0:38ccae254a29 56 SerialBase *handler = (SerialBase*)id;
mega64 0:38ccae254a29 57 handler->_irq[irq_type].call();
mega64 0:38ccae254a29 58 }
mega64 0:38ccae254a29 59
mega64 0:38ccae254a29 60 int SerialBase::_base_getc() {
mega64 0:38ccae254a29 61 return serial_getc(&_serial);
mega64 0:38ccae254a29 62 }
mega64 0:38ccae254a29 63
mega64 0:38ccae254a29 64 int SerialBase::_base_putc(int c) {
mega64 0:38ccae254a29 65 serial_putc(&_serial, c);
mega64 0:38ccae254a29 66 return c;
mega64 0:38ccae254a29 67 }
mega64 0:38ccae254a29 68
mega64 0:38ccae254a29 69 void SerialBase::send_break() {
mega64 0:38ccae254a29 70 // Wait for 1.5 frames before clearing the break condition
mega64 0:38ccae254a29 71 // This will have different effects on our platforms, but should
mega64 0:38ccae254a29 72 // ensure that we keep the break active for at least one frame.
mega64 0:38ccae254a29 73 // We consider a full frame (1 start bit + 8 data bits bits +
mega64 0:38ccae254a29 74 // 1 parity bit + 2 stop bits = 12 bits) for computation.
mega64 0:38ccae254a29 75 // One bit time (in us) = 1000000/_baud
mega64 0:38ccae254a29 76 // Twelve bits: 12000000/baud delay
mega64 0:38ccae254a29 77 // 1.5 frames: 18000000/baud delay
mega64 0:38ccae254a29 78 serial_break_set(&_serial);
mega64 0:38ccae254a29 79 wait_us(18000000/_baud);
mega64 0:38ccae254a29 80 serial_break_clear(&_serial);
mega64 0:38ccae254a29 81 }
mega64 0:38ccae254a29 82
mega64 0:38ccae254a29 83 #if DEVICE_SERIAL_FC
stupidcode 12:ee1efe6181e7 84 void SerialBase::set_flow_control(Flow type, PinName flow1, PinName flow2) {
stupidcode 12:ee1efe6181e7 85
mega64 0:38ccae254a29 86 FlowControl flow_type = (FlowControl)type;
stupidcode 12:ee1efe6181e7 87
mega64 0:38ccae254a29 88 switch(type) {
mega64 0:38ccae254a29 89 case RTS:
stupidcode 12:ee1efe6181e7 90 //serial_set_flow_control(&_serial, flow_type, flow1, NC);
mega64 0:38ccae254a29 91 break;
mega64 0:38ccae254a29 92
mega64 0:38ccae254a29 93 case CTS:
stupidcode 12:ee1efe6181e7 94 //serial_set_flow_control(&_serial, flow_type, NC, flow1);
mega64 0:38ccae254a29 95 break;
mega64 0:38ccae254a29 96
mega64 0:38ccae254a29 97 case RTSCTS:
mega64 0:38ccae254a29 98 case Disabled:
stupidcode 12:ee1efe6181e7 99 //serial_set_flow_control(&_serial, flow_type, flow1, flow2);
mega64 0:38ccae254a29 100 break;
mega64 0:38ccae254a29 101
mega64 0:38ccae254a29 102 default:
mega64 0:38ccae254a29 103 break;
stupidcode 12:ee1efe6181e7 104
stupidcode 12:ee1efe6181e7 105 }
mega64 0:38ccae254a29 106 }
mega64 0:38ccae254a29 107 #endif
mega64 0:38ccae254a29 108
mega64 0:38ccae254a29 109 } // namespace mbed
mega64 0:38ccae254a29 110
mega64 0:38ccae254a29 111 #endif