mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
ebf95d2545
This commit introduces a more robust GPIO mocking mechanism by utilizing a 2-dimensional array. Each element of the array holds a gpio_mock_t structure describing a pin's attributes such as value, mode, flank, interruption callback, and callback argument. This enhancement allows for the arbitrary simulation of GPIOs across various microcontroller architectures using the current API, while maintaining consistency through the use of the GPIO_PIN macro. Additionally, it should be noted that only the maximum number of ports and maximum number of pins can be altered according to the context. The implemented API in gpio_mock.c remains rudimentary, providing no validation but fulfilling the required functions. However, it remains customizable as all its functions are marked as weak. Signed-off-by: Gilles DOFFE <g.doffe@gmail.com>
102 lines
1.7 KiB
C
102 lines
1.7 KiB
C
/*
|
|
* Copyright (C) 2015 Takuo Yonezawa <Yonezawa-T2@mail.dnp.co.jp>
|
|
*
|
|
* This file is subject to the terms and conditions of the GNU Lesser General
|
|
* Public License v2.1. See the file LICENSE in the top level directory for
|
|
* more details.
|
|
*/
|
|
|
|
/**
|
|
* @ingroup cpu_native
|
|
* @ingroup drivers_periph_gpio
|
|
* @{
|
|
*
|
|
* @file
|
|
* @brief empty GPIO implementation
|
|
*
|
|
* @author Takuo Yonezawa <Yonezawa-T2@mail.dnp.co.jp>
|
|
*/
|
|
|
|
#include "periph/gpio.h"
|
|
|
|
/**
|
|
* @brief Mocked GPIO array
|
|
*/
|
|
gpio_mock_t gpio_mock[GPIO_PORT_MAX][GPIO_PIN_MAX];
|
|
|
|
__attribute__((weak)) int gpio_init(gpio_t pin, gpio_mode_t mode) {
|
|
(void) pin;
|
|
(void) mode;
|
|
|
|
if (pin) {
|
|
pin->mode = mode;
|
|
pin->value = 0;
|
|
return 0;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
__attribute__((weak)) int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank,
|
|
gpio_cb_t cb, void *arg)
|
|
{
|
|
(void) cb;
|
|
(void) arg;
|
|
|
|
if (pin) {
|
|
pin->mode = mode;
|
|
pin->flank = flank;
|
|
pin->value = 0;
|
|
pin->cb = cb;
|
|
pin->arg = arg;
|
|
|
|
return 0;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
__attribute__((weak)) void gpio_irq_enable(gpio_t pin)
|
|
{
|
|
(void) pin;
|
|
}
|
|
|
|
__attribute__((weak)) void gpio_irq_disable(gpio_t pin)
|
|
{
|
|
(void) pin;
|
|
}
|
|
|
|
__attribute__((weak)) int gpio_read(gpio_t pin) {
|
|
if (pin) {
|
|
return pin->value;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
__attribute__((weak)) void gpio_set(gpio_t pin) {
|
|
if (pin) {
|
|
pin->value = 1;
|
|
}
|
|
}
|
|
|
|
__attribute__((weak)) void gpio_clear(gpio_t pin) {
|
|
if (pin) {
|
|
pin->value = 0;
|
|
}
|
|
}
|
|
|
|
__attribute__((weak)) void gpio_toggle(gpio_t pin) {
|
|
if (pin) {
|
|
pin->value ^= 1;
|
|
}
|
|
}
|
|
|
|
__attribute__((weak)) void gpio_write(gpio_t pin, int value) {
|
|
if (pin) {
|
|
pin->value = value;
|
|
}
|
|
}
|
|
|
|
/** @} */
|