Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466

Dependencies:   ssd1331

Committer:
kadonotakashi
Date:
Thu Oct 11 02:27:46 2018 +0000
Revision:
3:f3764f852aa8
Parent:
0:8fdf9a60065b
Nucreo 446 + SSD1331 test version;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kadonotakashi 0:8fdf9a60065b 1 /* mbed Microcontroller Library
kadonotakashi 0:8fdf9a60065b 2 * Copyright (c) 2006-2012 ARM Limited
kadonotakashi 0:8fdf9a60065b 3 *
kadonotakashi 0:8fdf9a60065b 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
kadonotakashi 0:8fdf9a60065b 5 * of this software and associated documentation files (the "Software"), to deal
kadonotakashi 0:8fdf9a60065b 6 * in the Software without restriction, including without limitation the rights
kadonotakashi 0:8fdf9a60065b 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
kadonotakashi 0:8fdf9a60065b 8 * copies of the Software, and to permit persons to whom the Software is
kadonotakashi 0:8fdf9a60065b 9 * furnished to do so, subject to the following conditions:
kadonotakashi 0:8fdf9a60065b 10 *
kadonotakashi 0:8fdf9a60065b 11 * The above copyright notice and this permission notice shall be included in
kadonotakashi 0:8fdf9a60065b 12 * all copies or substantial portions of the Software.
kadonotakashi 0:8fdf9a60065b 13 *
kadonotakashi 0:8fdf9a60065b 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
kadonotakashi 0:8fdf9a60065b 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
kadonotakashi 0:8fdf9a60065b 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
kadonotakashi 0:8fdf9a60065b 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
kadonotakashi 0:8fdf9a60065b 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
kadonotakashi 0:8fdf9a60065b 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
kadonotakashi 0:8fdf9a60065b 20 * SOFTWARE.
kadonotakashi 0:8fdf9a60065b 21 */
kadonotakashi 0:8fdf9a60065b 22 #include "rtos/Semaphore.h"
kadonotakashi 0:8fdf9a60065b 23 #include "rtos/Kernel.h"
kadonotakashi 0:8fdf9a60065b 24 #include "platform/mbed_assert.h"
kadonotakashi 0:8fdf9a60065b 25
kadonotakashi 0:8fdf9a60065b 26 #include <string.h>
kadonotakashi 0:8fdf9a60065b 27
kadonotakashi 0:8fdf9a60065b 28 namespace rtos {
kadonotakashi 0:8fdf9a60065b 29
kadonotakashi 0:8fdf9a60065b 30 Semaphore::Semaphore(int32_t count) {
kadonotakashi 0:8fdf9a60065b 31 constructor(count, 0xffff);
kadonotakashi 0:8fdf9a60065b 32 }
kadonotakashi 0:8fdf9a60065b 33
kadonotakashi 0:8fdf9a60065b 34 Semaphore::Semaphore(int32_t count, uint16_t max_count) {
kadonotakashi 0:8fdf9a60065b 35 constructor(count, max_count);
kadonotakashi 0:8fdf9a60065b 36 }
kadonotakashi 0:8fdf9a60065b 37
kadonotakashi 0:8fdf9a60065b 38 void Semaphore::constructor(int32_t count, uint16_t max_count) {
kadonotakashi 0:8fdf9a60065b 39 memset(&_obj_mem, 0, sizeof(_obj_mem));
kadonotakashi 0:8fdf9a60065b 40 osSemaphoreAttr_t attr = { 0 };
kadonotakashi 0:8fdf9a60065b 41 attr.cb_mem = &_obj_mem;
kadonotakashi 0:8fdf9a60065b 42 attr.cb_size = sizeof(_obj_mem);
kadonotakashi 0:8fdf9a60065b 43 _id = osSemaphoreNew(max_count, count, &attr);
kadonotakashi 0:8fdf9a60065b 44 MBED_ASSERT(_id != NULL);
kadonotakashi 0:8fdf9a60065b 45 }
kadonotakashi 0:8fdf9a60065b 46
kadonotakashi 0:8fdf9a60065b 47 int32_t Semaphore::wait(uint32_t millisec) {
kadonotakashi 0:8fdf9a60065b 48 osStatus_t stat = osSemaphoreAcquire(_id, millisec);
kadonotakashi 0:8fdf9a60065b 49 switch (stat) {
kadonotakashi 0:8fdf9a60065b 50 case osOK:
kadonotakashi 0:8fdf9a60065b 51 return osSemaphoreGetCount(_id) + 1;
kadonotakashi 0:8fdf9a60065b 52 case osErrorTimeout:
kadonotakashi 0:8fdf9a60065b 53 case osErrorResource:
kadonotakashi 0:8fdf9a60065b 54 return 0;
kadonotakashi 0:8fdf9a60065b 55 case osErrorParameter:
kadonotakashi 0:8fdf9a60065b 56 default:
kadonotakashi 0:8fdf9a60065b 57 return -1;
kadonotakashi 0:8fdf9a60065b 58 }
kadonotakashi 0:8fdf9a60065b 59 }
kadonotakashi 0:8fdf9a60065b 60
kadonotakashi 0:8fdf9a60065b 61 int32_t Semaphore::wait_until(uint64_t millisec) {
kadonotakashi 0:8fdf9a60065b 62 uint64_t now = Kernel::get_ms_count();
kadonotakashi 0:8fdf9a60065b 63
kadonotakashi 0:8fdf9a60065b 64 if (now >= millisec) {
kadonotakashi 0:8fdf9a60065b 65 return wait(0);
kadonotakashi 0:8fdf9a60065b 66 } else if (millisec - now >= osWaitForever) {
kadonotakashi 0:8fdf9a60065b 67 // API permits early return
kadonotakashi 0:8fdf9a60065b 68 return wait(osWaitForever - 1);
kadonotakashi 0:8fdf9a60065b 69 } else {
kadonotakashi 0:8fdf9a60065b 70 return wait(millisec - now);
kadonotakashi 0:8fdf9a60065b 71 }
kadonotakashi 0:8fdf9a60065b 72 }
kadonotakashi 0:8fdf9a60065b 73
kadonotakashi 0:8fdf9a60065b 74 osStatus Semaphore::release(void) {
kadonotakashi 0:8fdf9a60065b 75 return osSemaphoreRelease(_id);
kadonotakashi 0:8fdf9a60065b 76 }
kadonotakashi 0:8fdf9a60065b 77
kadonotakashi 0:8fdf9a60065b 78 Semaphore::~Semaphore() {
kadonotakashi 0:8fdf9a60065b 79 osSemaphoreDelete(_id);
kadonotakashi 0:8fdf9a60065b 80 }
kadonotakashi 0:8fdf9a60065b 81
kadonotakashi 0:8fdf9a60065b 82 }