Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466

Dependencies:   ssd1331

Committer:
kadonotakashi
Date:
Wed Oct 10 00:33:53 2018 +0000
Revision:
0:8fdf9a60065b
how to make mbed librry

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-2017 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 #ifndef MAIL_H
kadonotakashi 0:8fdf9a60065b 23 #define MAIL_H
kadonotakashi 0:8fdf9a60065b 24
kadonotakashi 0:8fdf9a60065b 25 #include <stdint.h>
kadonotakashi 0:8fdf9a60065b 26 #include <string.h>
kadonotakashi 0:8fdf9a60065b 27
kadonotakashi 0:8fdf9a60065b 28 #include "Queue.h"
kadonotakashi 0:8fdf9a60065b 29 #include "MemoryPool.h"
kadonotakashi 0:8fdf9a60065b 30 #include "cmsis_os2.h"
kadonotakashi 0:8fdf9a60065b 31 #include "mbed_rtos_storage.h"
kadonotakashi 0:8fdf9a60065b 32 #include "mbed_rtos1_types.h"
kadonotakashi 0:8fdf9a60065b 33
kadonotakashi 0:8fdf9a60065b 34 #include "platform/NonCopyable.h"
kadonotakashi 0:8fdf9a60065b 35
kadonotakashi 0:8fdf9a60065b 36 using namespace rtos;
kadonotakashi 0:8fdf9a60065b 37
kadonotakashi 0:8fdf9a60065b 38 namespace rtos {
kadonotakashi 0:8fdf9a60065b 39 /** \addtogroup rtos */
kadonotakashi 0:8fdf9a60065b 40 /** @{*/
kadonotakashi 0:8fdf9a60065b 41 /**
kadonotakashi 0:8fdf9a60065b 42 * \defgroup rtos_Mail Mail class
kadonotakashi 0:8fdf9a60065b 43 * @{
kadonotakashi 0:8fdf9a60065b 44 */
kadonotakashi 0:8fdf9a60065b 45
kadonotakashi 0:8fdf9a60065b 46 /** The Mail class allow to control, send, receive, or wait for mail.
kadonotakashi 0:8fdf9a60065b 47 A mail is a memory block that is send to a thread or interrupt service routine.
kadonotakashi 0:8fdf9a60065b 48 @tparam T data type of a single message element.
kadonotakashi 0:8fdf9a60065b 49 @tparam queue_sz maximum number of messages in queue.
kadonotakashi 0:8fdf9a60065b 50
kadonotakashi 0:8fdf9a60065b 51 @note
kadonotakashi 0:8fdf9a60065b 52 Memory considerations: The mail data store and control structures will be created on current thread's stack,
kadonotakashi 0:8fdf9a60065b 53 both for the mbed OS and underlying RTOS objects (static or dynamic RTOS memory pools are not being used).
kadonotakashi 0:8fdf9a60065b 54 */
kadonotakashi 0:8fdf9a60065b 55 template<typename T, uint32_t queue_sz>
kadonotakashi 0:8fdf9a60065b 56 class Mail : private mbed::NonCopyable<Mail<T, queue_sz> > {
kadonotakashi 0:8fdf9a60065b 57 public:
kadonotakashi 0:8fdf9a60065b 58 /** Create and Initialize Mail queue.
kadonotakashi 0:8fdf9a60065b 59 *
kadonotakashi 0:8fdf9a60065b 60 * @note You cannot call this function from ISR context.
kadonotakashi 0:8fdf9a60065b 61 */
kadonotakashi 0:8fdf9a60065b 62 Mail() { };
kadonotakashi 0:8fdf9a60065b 63
kadonotakashi 0:8fdf9a60065b 64 /** Check if the mail queue is empty
kadonotakashi 0:8fdf9a60065b 65 *
kadonotakashi 0:8fdf9a60065b 66 * @return True if the mail queue is empty, false if not
kadonotakashi 0:8fdf9a60065b 67 *
kadonotakashi 0:8fdf9a60065b 68 * @note You may call this function from ISR context.
kadonotakashi 0:8fdf9a60065b 69 */
kadonotakashi 0:8fdf9a60065b 70 bool empty() const {
kadonotakashi 0:8fdf9a60065b 71 return _queue.empty();
kadonotakashi 0:8fdf9a60065b 72 }
kadonotakashi 0:8fdf9a60065b 73
kadonotakashi 0:8fdf9a60065b 74 /** Check if the mail queue is full
kadonotakashi 0:8fdf9a60065b 75 *
kadonotakashi 0:8fdf9a60065b 76 * @return True if the mail queue is full, false if not
kadonotakashi 0:8fdf9a60065b 77 *
kadonotakashi 0:8fdf9a60065b 78 * @note You may call this function from ISR context.
kadonotakashi 0:8fdf9a60065b 79 */
kadonotakashi 0:8fdf9a60065b 80 bool full() const {
kadonotakashi 0:8fdf9a60065b 81 return _queue.full();
kadonotakashi 0:8fdf9a60065b 82 }
kadonotakashi 0:8fdf9a60065b 83
kadonotakashi 0:8fdf9a60065b 84 /** Allocate a memory block of type T
kadonotakashi 0:8fdf9a60065b 85 @param millisec timeout value or 0 in case of no time-out. (default: 0).
kadonotakashi 0:8fdf9a60065b 86 @return pointer to memory block that can be filled with mail or NULL in case error.
kadonotakashi 0:8fdf9a60065b 87
kadonotakashi 0:8fdf9a60065b 88 @note You may call this function from ISR context if the millisec parameter is set to 0.
kadonotakashi 0:8fdf9a60065b 89 */
kadonotakashi 0:8fdf9a60065b 90 T* alloc(uint32_t millisec=0) {
kadonotakashi 0:8fdf9a60065b 91 return _pool.alloc();
kadonotakashi 0:8fdf9a60065b 92 }
kadonotakashi 0:8fdf9a60065b 93
kadonotakashi 0:8fdf9a60065b 94 /** Allocate a memory block of type T and set memory block to zero.
kadonotakashi 0:8fdf9a60065b 95 @param millisec timeout value or 0 in case of no time-out. (default: 0).
kadonotakashi 0:8fdf9a60065b 96 @return pointer to memory block that can be filled with mail or NULL in case error.
kadonotakashi 0:8fdf9a60065b 97
kadonotakashi 0:8fdf9a60065b 98 @note You may call this function from ISR context if the millisec parameter is set to 0.
kadonotakashi 0:8fdf9a60065b 99 */
kadonotakashi 0:8fdf9a60065b 100 T* calloc(uint32_t millisec=0) {
kadonotakashi 0:8fdf9a60065b 101 return _pool.calloc();
kadonotakashi 0:8fdf9a60065b 102 }
kadonotakashi 0:8fdf9a60065b 103
kadonotakashi 0:8fdf9a60065b 104 /** Put a mail in the queue.
kadonotakashi 0:8fdf9a60065b 105 @param mptr memory block previously allocated with Mail::alloc or Mail::calloc.
kadonotakashi 0:8fdf9a60065b 106 @return status code that indicates the execution status of the function.
kadonotakashi 0:8fdf9a60065b 107
kadonotakashi 0:8fdf9a60065b 108 @note You may call this function from ISR context.
kadonotakashi 0:8fdf9a60065b 109 */
kadonotakashi 0:8fdf9a60065b 110 osStatus put(T *mptr) {
kadonotakashi 0:8fdf9a60065b 111 return _queue.put(mptr);
kadonotakashi 0:8fdf9a60065b 112 }
kadonotakashi 0:8fdf9a60065b 113
kadonotakashi 0:8fdf9a60065b 114 /** Get a mail from a queue.
kadonotakashi 0:8fdf9a60065b 115 @param millisec timeout value or 0 in case of no time-out. (default: osWaitForever).
kadonotakashi 0:8fdf9a60065b 116 @return event that contains mail information or error code.
kadonotakashi 0:8fdf9a60065b 117
kadonotakashi 0:8fdf9a60065b 118 @note You may call this function from ISR context if the millisec parameter is set to 0.
kadonotakashi 0:8fdf9a60065b 119 */
kadonotakashi 0:8fdf9a60065b 120 osEvent get(uint32_t millisec=osWaitForever) {
kadonotakashi 0:8fdf9a60065b 121 osEvent evt = _queue.get(millisec);
kadonotakashi 0:8fdf9a60065b 122 if (evt.status == osEventMessage) {
kadonotakashi 0:8fdf9a60065b 123 evt.status = osEventMail;
kadonotakashi 0:8fdf9a60065b 124 }
kadonotakashi 0:8fdf9a60065b 125 return evt;
kadonotakashi 0:8fdf9a60065b 126 }
kadonotakashi 0:8fdf9a60065b 127
kadonotakashi 0:8fdf9a60065b 128 /** Free a memory block from a mail.
kadonotakashi 0:8fdf9a60065b 129 @param mptr pointer to the memory block that was obtained with Mail::get.
kadonotakashi 0:8fdf9a60065b 130 @return status code that indicates the execution status of the function.
kadonotakashi 0:8fdf9a60065b 131
kadonotakashi 0:8fdf9a60065b 132 @note You may call this function from ISR context.
kadonotakashi 0:8fdf9a60065b 133 */
kadonotakashi 0:8fdf9a60065b 134 osStatus free(T *mptr) {
kadonotakashi 0:8fdf9a60065b 135 return _pool.free(mptr);
kadonotakashi 0:8fdf9a60065b 136 }
kadonotakashi 0:8fdf9a60065b 137
kadonotakashi 0:8fdf9a60065b 138 private:
kadonotakashi 0:8fdf9a60065b 139 Queue<T, queue_sz> _queue;
kadonotakashi 0:8fdf9a60065b 140 MemoryPool<T, queue_sz> _pool;
kadonotakashi 0:8fdf9a60065b 141 };
kadonotakashi 0:8fdf9a60065b 142
kadonotakashi 0:8fdf9a60065b 143 /** @}*/
kadonotakashi 0:8fdf9a60065b 144 /** @}*/
kadonotakashi 0:8fdf9a60065b 145
kadonotakashi 0:8fdf9a60065b 146 }
kadonotakashi 0:8fdf9a60065b 147
kadonotakashi 0:8fdf9a60065b 148 #endif
kadonotakashi 0:8fdf9a60065b 149
kadonotakashi 0:8fdf9a60065b 150
kadonotakashi 0:8fdf9a60065b 151