lol
Fork of Application by
mbed-dev/platform/mbed_board.c@12:3a30cdffa27c, 2018-01-21 (annotated)
- Committer:
- danix
- Date:
- Sun Jan 21 22:28:30 2018 +0000
- Revision:
- 12:3a30cdffa27c
- Parent:
- 10:41552d038a69
Working acelerometer and mouse
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Zaitsev | 10:41552d038a69 | 1 | /* mbed Microcontroller Library |
Zaitsev | 10:41552d038a69 | 2 | * Copyright (c) 2006-2013 ARM Limited |
Zaitsev | 10:41552d038a69 | 3 | * |
Zaitsev | 10:41552d038a69 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Zaitsev | 10:41552d038a69 | 5 | * you may not use this file except in compliance with the License. |
Zaitsev | 10:41552d038a69 | 6 | * You may obtain a copy of the License at |
Zaitsev | 10:41552d038a69 | 7 | * |
Zaitsev | 10:41552d038a69 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Zaitsev | 10:41552d038a69 | 9 | * |
Zaitsev | 10:41552d038a69 | 10 | * Unless required by applicable law or agreed to in writing, software |
Zaitsev | 10:41552d038a69 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Zaitsev | 10:41552d038a69 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Zaitsev | 10:41552d038a69 | 13 | * See the License for the specific language governing permissions and |
Zaitsev | 10:41552d038a69 | 14 | * limitations under the License. |
Zaitsev | 10:41552d038a69 | 15 | */ |
Zaitsev | 10:41552d038a69 | 16 | #include <stdio.h> |
Zaitsev | 10:41552d038a69 | 17 | #include "hal/gpio_api.h" |
Zaitsev | 10:41552d038a69 | 18 | #include "platform/wait_api.h" |
Zaitsev | 10:41552d038a69 | 19 | #include "platform/toolchain.h" |
Zaitsev | 10:41552d038a69 | 20 | #include "platform/mbed_interface.h" |
Zaitsev | 10:41552d038a69 | 21 | #include "platform/critical.h" |
Zaitsev | 10:41552d038a69 | 22 | #include "hal/serial_api.h" |
Zaitsev | 10:41552d038a69 | 23 | |
Zaitsev | 10:41552d038a69 | 24 | #if DEVICE_SERIAL |
Zaitsev | 10:41552d038a69 | 25 | extern int stdio_uart_inited; |
Zaitsev | 10:41552d038a69 | 26 | extern serial_t stdio_uart; |
Zaitsev | 10:41552d038a69 | 27 | #endif |
Zaitsev | 10:41552d038a69 | 28 | |
Zaitsev | 10:41552d038a69 | 29 | WEAK void mbed_die(void) { |
Zaitsev | 10:41552d038a69 | 30 | #if !defined (NRF51_H) && !defined(TARGET_EFM32) |
Zaitsev | 10:41552d038a69 | 31 | core_util_critical_section_enter(); |
Zaitsev | 10:41552d038a69 | 32 | #endif |
Zaitsev | 10:41552d038a69 | 33 | #if (DEVICE_ERROR_RED == 1) |
Zaitsev | 10:41552d038a69 | 34 | gpio_t led_red; gpio_init_out(&led_red, LED_RED); |
Zaitsev | 10:41552d038a69 | 35 | #elif (DEVICE_ERROR_PATTERN == 1) |
Zaitsev | 10:41552d038a69 | 36 | gpio_t led_1; gpio_init_out(&led_1, LED1); |
Zaitsev | 10:41552d038a69 | 37 | gpio_t led_2; gpio_init_out(&led_2, LED2); |
Zaitsev | 10:41552d038a69 | 38 | gpio_t led_3; gpio_init_out(&led_3, LED3); |
Zaitsev | 10:41552d038a69 | 39 | gpio_t led_4; gpio_init_out(&led_4, LED4); |
Zaitsev | 10:41552d038a69 | 40 | #endif |
Zaitsev | 10:41552d038a69 | 41 | |
Zaitsev | 10:41552d038a69 | 42 | while (1) { |
Zaitsev | 10:41552d038a69 | 43 | #if (DEVICE_ERROR_RED == 1) |
Zaitsev | 10:41552d038a69 | 44 | gpio_write(&led_red, 1); |
Zaitsev | 10:41552d038a69 | 45 | |
Zaitsev | 10:41552d038a69 | 46 | #elif (DEVICE_ERROR_PATTERN == 1) |
Zaitsev | 10:41552d038a69 | 47 | gpio_write(&led_1, 1); |
Zaitsev | 10:41552d038a69 | 48 | gpio_write(&led_2, 0); |
Zaitsev | 10:41552d038a69 | 49 | gpio_write(&led_3, 0); |
Zaitsev | 10:41552d038a69 | 50 | gpio_write(&led_4, 1); |
Zaitsev | 10:41552d038a69 | 51 | #endif |
Zaitsev | 10:41552d038a69 | 52 | |
Zaitsev | 10:41552d038a69 | 53 | wait_ms(150); |
Zaitsev | 10:41552d038a69 | 54 | |
Zaitsev | 10:41552d038a69 | 55 | #if (DEVICE_ERROR_RED == 1) |
Zaitsev | 10:41552d038a69 | 56 | gpio_write(&led_red, 0); |
Zaitsev | 10:41552d038a69 | 57 | |
Zaitsev | 10:41552d038a69 | 58 | #elif (DEVICE_ERROR_PATTERN == 1) |
Zaitsev | 10:41552d038a69 | 59 | gpio_write(&led_1, 0); |
Zaitsev | 10:41552d038a69 | 60 | gpio_write(&led_2, 1); |
Zaitsev | 10:41552d038a69 | 61 | gpio_write(&led_3, 1); |
Zaitsev | 10:41552d038a69 | 62 | gpio_write(&led_4, 0); |
Zaitsev | 10:41552d038a69 | 63 | #endif |
Zaitsev | 10:41552d038a69 | 64 | |
Zaitsev | 10:41552d038a69 | 65 | wait_ms(150); |
Zaitsev | 10:41552d038a69 | 66 | } |
Zaitsev | 10:41552d038a69 | 67 | } |
Zaitsev | 10:41552d038a69 | 68 | |
Zaitsev | 10:41552d038a69 | 69 | void mbed_error_printf(const char* format, ...) { |
Zaitsev | 10:41552d038a69 | 70 | va_list arg; |
Zaitsev | 10:41552d038a69 | 71 | va_start(arg, format); |
Zaitsev | 10:41552d038a69 | 72 | mbed_error_vfprintf(format, arg); |
Zaitsev | 10:41552d038a69 | 73 | va_end(arg); |
Zaitsev | 10:41552d038a69 | 74 | } |
Zaitsev | 10:41552d038a69 | 75 | |
Zaitsev | 10:41552d038a69 | 76 | void mbed_error_vfprintf(const char * format, va_list arg) { |
Zaitsev | 10:41552d038a69 | 77 | #if DEVICE_SERIAL |
Zaitsev | 10:41552d038a69 | 78 | core_util_critical_section_enter(); |
Zaitsev | 10:41552d038a69 | 79 | char buffer[128]; |
Zaitsev | 10:41552d038a69 | 80 | int size = vsprintf(buffer, format, arg); |
Zaitsev | 10:41552d038a69 | 81 | if (size > 0) { |
Zaitsev | 10:41552d038a69 | 82 | if (!stdio_uart_inited) { |
Zaitsev | 10:41552d038a69 | 83 | serial_init(&stdio_uart, STDIO_UART_TX, STDIO_UART_RX); |
Zaitsev | 10:41552d038a69 | 84 | } |
Zaitsev | 10:41552d038a69 | 85 | for (int i = 0; i < size; i++) { |
Zaitsev | 10:41552d038a69 | 86 | serial_putc(&stdio_uart, buffer[i]); |
Zaitsev | 10:41552d038a69 | 87 | } |
Zaitsev | 10:41552d038a69 | 88 | } |
Zaitsev | 10:41552d038a69 | 89 | core_util_critical_section_exit(); |
Zaitsev | 10:41552d038a69 | 90 | #endif |
Zaitsev | 10:41552d038a69 | 91 | } |