PokittoLib with changes to lcd refresh etc.

Dependents:   Pokittris

Fork of Pokitto by Pokitto Community Team

This is a fork by user @Spinal, and is used in Pokittris for testing. Do not import this to your own program.

Committer:
Pokitto
Date:
Sat Oct 07 21:31:12 2017 +0000
Revision:
5:7e5c566b1760
mbed-pokitto integrated

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 5:7e5c566b1760 1 /* mbed Microcontroller Library
Pokitto 5:7e5c566b1760 2 * Copyright (c) 2015 ARM Limited
Pokitto 5:7e5c566b1760 3 *
Pokitto 5:7e5c566b1760 4 * Licensed under the Apache License, Version 2.0 (the "License");
Pokitto 5:7e5c566b1760 5 * you may not use this file except in compliance with the License.
Pokitto 5:7e5c566b1760 6 * You may obtain a copy of the License at
Pokitto 5:7e5c566b1760 7 *
Pokitto 5:7e5c566b1760 8 * http://www.apache.org/licenses/LICENSE-2.0
Pokitto 5:7e5c566b1760 9 *
Pokitto 5:7e5c566b1760 10 * Unless required by applicable law or agreed to in writing, software
Pokitto 5:7e5c566b1760 11 * distributed under the License is distributed on an "AS IS" BASIS,
Pokitto 5:7e5c566b1760 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Pokitto 5:7e5c566b1760 13 * See the License for the specific language governing permissions and
Pokitto 5:7e5c566b1760 14 * limitations under the License.
Pokitto 5:7e5c566b1760 15 */
Pokitto 5:7e5c566b1760 16 #ifndef MBED_TICKER_API_H
Pokitto 5:7e5c566b1760 17 #define MBED_TICKER_API_H
Pokitto 5:7e5c566b1760 18
Pokitto 5:7e5c566b1760 19 #include "device.h"
Pokitto 5:7e5c566b1760 20
Pokitto 5:7e5c566b1760 21 typedef uint32_t timestamp_t;
Pokitto 5:7e5c566b1760 22
Pokitto 5:7e5c566b1760 23 /** Ticker's event structure
Pokitto 5:7e5c566b1760 24 */
Pokitto 5:7e5c566b1760 25 typedef struct ticker_event_s {
Pokitto 5:7e5c566b1760 26 timestamp_t timestamp; /**< Event's timestamp */
Pokitto 5:7e5c566b1760 27 uint32_t id; /**< TimerEvent object */
Pokitto 5:7e5c566b1760 28 struct ticker_event_s *next; /**< Next event in the queue */
Pokitto 5:7e5c566b1760 29 } ticker_event_t;
Pokitto 5:7e5c566b1760 30
Pokitto 5:7e5c566b1760 31 typedef void (*ticker_event_handler)(uint32_t id);
Pokitto 5:7e5c566b1760 32
Pokitto 5:7e5c566b1760 33 /** Ticker's interface structure - required API for a ticker
Pokitto 5:7e5c566b1760 34 */
Pokitto 5:7e5c566b1760 35 typedef struct {
Pokitto 5:7e5c566b1760 36 void (*init)(void); /**< Init function */
Pokitto 5:7e5c566b1760 37 uint32_t (*read)(void); /**< Read function */
Pokitto 5:7e5c566b1760 38 void (*disable_interrupt)(void); /**< Disable interrupt function */
Pokitto 5:7e5c566b1760 39 void (*clear_interrupt)(void); /**< Clear interrupt function */
Pokitto 5:7e5c566b1760 40 void (*set_interrupt)(timestamp_t timestamp); /**< Set interrupt function */
Pokitto 5:7e5c566b1760 41 } ticker_interface_t;
Pokitto 5:7e5c566b1760 42
Pokitto 5:7e5c566b1760 43 /** Tickers events queue structure
Pokitto 5:7e5c566b1760 44 */
Pokitto 5:7e5c566b1760 45 typedef struct {
Pokitto 5:7e5c566b1760 46 ticker_event_handler event_handler; /**< Event handler */
Pokitto 5:7e5c566b1760 47 ticker_event_t *head; /**< A pointer to head */
Pokitto 5:7e5c566b1760 48 } ticker_event_queue_t;
Pokitto 5:7e5c566b1760 49
Pokitto 5:7e5c566b1760 50 /** Tickers data structure
Pokitto 5:7e5c566b1760 51 */
Pokitto 5:7e5c566b1760 52 typedef struct {
Pokitto 5:7e5c566b1760 53 const ticker_interface_t *interface; /**< Ticker's interface */
Pokitto 5:7e5c566b1760 54 ticker_event_queue_t *queue; /**< Ticker's events queue */
Pokitto 5:7e5c566b1760 55 } ticker_data_t;
Pokitto 5:7e5c566b1760 56
Pokitto 5:7e5c566b1760 57 #ifdef __cplusplus
Pokitto 5:7e5c566b1760 58 extern "C" {
Pokitto 5:7e5c566b1760 59 #endif
Pokitto 5:7e5c566b1760 60
Pokitto 5:7e5c566b1760 61 /** Initialize a ticker and sets the event handler
Pokitto 5:7e5c566b1760 62 *
Pokitto 5:7e5c566b1760 63 * @param data The ticker's data
Pokitto 5:7e5c566b1760 64 * @param handler A handler to be set
Pokitto 5:7e5c566b1760 65 */
Pokitto 5:7e5c566b1760 66 void ticker_set_handler(const ticker_data_t *const data, ticker_event_handler handler);
Pokitto 5:7e5c566b1760 67
Pokitto 5:7e5c566b1760 68 /** Irq handler which goes through the events to trigger events in the past.
Pokitto 5:7e5c566b1760 69 *
Pokitto 5:7e5c566b1760 70 * @param data The ticker's data
Pokitto 5:7e5c566b1760 71 */
Pokitto 5:7e5c566b1760 72 void ticker_irq_handler(const ticker_data_t *const data);
Pokitto 5:7e5c566b1760 73
Pokitto 5:7e5c566b1760 74 /** Remove an event from the queue
Pokitto 5:7e5c566b1760 75 *
Pokitto 5:7e5c566b1760 76 * @param data The ticker's data
Pokitto 5:7e5c566b1760 77 * @param obj The event's queue to be removed
Pokitto 5:7e5c566b1760 78 */
Pokitto 5:7e5c566b1760 79 void ticker_remove_event(const ticker_data_t *const data, ticker_event_t *obj);
Pokitto 5:7e5c566b1760 80
Pokitto 5:7e5c566b1760 81 /** Insert an event from the queue
Pokitto 5:7e5c566b1760 82 *
Pokitto 5:7e5c566b1760 83 * @param data The ticker's data
Pokitto 5:7e5c566b1760 84 * @param obj The event's queue to be removed
Pokitto 5:7e5c566b1760 85 * @param timestamp The event's timestamp
Pokitto 5:7e5c566b1760 86 * @param id The event object
Pokitto 5:7e5c566b1760 87 */
Pokitto 5:7e5c566b1760 88 void ticker_insert_event(const ticker_data_t *const data, ticker_event_t *obj, timestamp_t timestamp, uint32_t id);
Pokitto 5:7e5c566b1760 89
Pokitto 5:7e5c566b1760 90 /** Read the current ticker's timestamp
Pokitto 5:7e5c566b1760 91 *
Pokitto 5:7e5c566b1760 92 * @param data The ticker's data
Pokitto 5:7e5c566b1760 93 * @return The current timestamp
Pokitto 5:7e5c566b1760 94 */
Pokitto 5:7e5c566b1760 95 timestamp_t ticker_read(const ticker_data_t *const data);
Pokitto 5:7e5c566b1760 96
Pokitto 5:7e5c566b1760 97 /** Read the next event's timestamp
Pokitto 5:7e5c566b1760 98 *
Pokitto 5:7e5c566b1760 99 * @param data The ticker's data
Pokitto 5:7e5c566b1760 100 * @return 1 if timestamp is pending event, 0 if there's no event pending
Pokitto 5:7e5c566b1760 101 */
Pokitto 5:7e5c566b1760 102 int ticker_get_next_timestamp(const ticker_data_t *const data, timestamp_t *timestamp);
Pokitto 5:7e5c566b1760 103
Pokitto 5:7e5c566b1760 104 #ifdef __cplusplus
Pokitto 5:7e5c566b1760 105 }
Pokitto 5:7e5c566b1760 106 #endif
Pokitto 5:7e5c566b1760 107
Pokitto 5:7e5c566b1760 108 #endif