Private
Public Access
2
0

mock: added mraa mock platform infra and GPIO implementation

Mock platform allows one to use mraa without having any real HW.

This commit makes necessary foundational changes and implements
GPIO functionality as well as adds respective tests.

Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Alex Tereschenko
2016-06-26 17:55:14 +02:00
committed by Brendan Le Foll
parent 593fd0be54
commit bcb6adc551
24 changed files with 827 additions and 8 deletions

40
include/mock/mock_board.h Normal file
View File

@@ -0,0 +1,40 @@
/*
* Author: Alex Tereschenko <alext.mkrs@gmail.com>
* Copyright (c) 2016 Alex Tereschenko.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "mraa_internal.h"
#define MRAA_MOCK_PINCOUNT 1
mraa_board_t*
mraa_mock_board();
#ifdef __cplusplus
}
#endif

View File

@@ -48,6 +48,7 @@ typedef struct {
mraa_result_t (*gpio_dir_replace) (mraa_gpio_context dev, mraa_gpio_dir_t dir);
mraa_result_t (*gpio_dir_pre) (mraa_gpio_context dev, mraa_gpio_dir_t dir);
mraa_result_t (*gpio_dir_post) (mraa_gpio_context dev, mraa_gpio_dir_t dir);
mraa_result_t (*gpio_read_dir_replace) (mraa_gpio_context dev, mraa_gpio_dir_t *dir);
int (*gpio_read_replace) (mraa_gpio_context dev);
mraa_result_t (*gpio_write_replace) (mraa_gpio_context dev, int value);
@@ -56,6 +57,8 @@ typedef struct {
mraa_result_t (*gpio_mmap_setup) (mraa_gpio_context dev, mraa_boolean_t en);
mraa_result_t (*gpio_interrupt_handler_init_replace) (mraa_gpio_context dev);
mraa_result_t (*gpio_wait_interrupt_replace) (mraa_gpio_context dev);
mraa_result_t (*gpio_isr_replace) (mraa_gpio_context dev, mraa_gpio_edge_t mode, void (*fptr)(void*), void* args);
mraa_result_t (*gpio_isr_exit_replace) (mraa_gpio_context dev);
mraa_result_t (*i2c_init_pre) (unsigned int bus);
mraa_result_t (*i2c_init_bus_replace) (mraa_i2c_context dev);

View File

@@ -62,6 +62,13 @@ mraa_platform_t mraa_x86_platform();
*/
mraa_platform_t mraa_arm_platform();
/**
* setup a mock platform
*
* @return mraa_platform_t of the init'ed platform
*/
mraa_platform_t mraa_mock_platform();
/**
* runtime detect running usb platform extender
*

View File

@@ -71,6 +71,10 @@ struct _gpio {
mraa_result_t (*mmap_write) (mraa_gpio_context dev, int value);
int (*mmap_read) (mraa_gpio_context dev);
mraa_adv_func_t* advance_func; /**< override function table */
#if defined(MOCKPLAT)
mraa_gpio_dir_t mock_dir; /**< mock direction of the pin */
int mock_state; /**< mock state of the pin */
#endif
/*@}*/
};