From 8a1c58bc7f1200869cd9ec81c5252fd0e7f89a0a Mon Sep 17 00:00:00 2001 From: Brendan Le Foll Date: Fri, 20 Jan 2017 08:29:18 +0000 Subject: [PATCH] peripheralman: Remove stray source files from pmraa Signed-off-by: Brendan Le Foll --- src/CMakeLists.txt | 6 - src/peripheralman/mraa.c | 371 ------------------------- src/peripheralman/peripheralman_aio.c | 64 ----- src/peripheralman/peripheralman_gpio.c | 180 ------------ src/peripheralman/peripheralman_i2c.c | 238 ---------------- src/peripheralman/peripheralman_pwm.c | 117 -------- src/peripheralman/peripheralman_spi.c | 257 ----------------- src/peripheralman/peripheralman_uart.c | 170 ----------- 8 files changed, 1403 deletions(-) delete mode 100644 src/peripheralman/mraa.c delete mode 100644 src/peripheralman/peripheralman_aio.c delete mode 100644 src/peripheralman/peripheralman_gpio.c delete mode 100644 src/peripheralman/peripheralman_i2c.c delete mode 100644 src/peripheralman/peripheralman_pwm.c delete mode 100644 src/peripheralman/peripheralman_spi.c delete mode 100644 src/peripheralman/peripheralman_uart.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c6f3c69..8850f82 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -104,12 +104,6 @@ set (mraa_LIB_MOCK_SRCS_NOAUTO set (mraa_LIB_PERIPHERALMAN_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/peripheralman/peripheralman.c -# ${PROJECT_SOURCE_DIR}/src/peripheralman/peripheralman_aio.c -# ${PROJECT_SOURCE_DIR}/src/peripheralman/peripheralman_gpio.c -# ${PROJECT_SOURCE_DIR}/src/peripheralman/peripheralman_i2c.c -# ${PROJECT_SOURCE_DIR}/src/peripheralman/peripheralman_pwm.c -# ${PROJECT_SOURCE_DIR}/src/peripheralman/peripheralman_spi.c -# ${PROJECT_SOURCE_DIR}/src/peripheralman/peripheralman_uart.c ) if (JSONPLAT) diff --git a/src/peripheralman/mraa.c b/src/peripheralman/mraa.c deleted file mode 100644 index abd0a64..0000000 --- a/src/peripheralman/mraa.c +++ /dev/null @@ -1,371 +0,0 @@ -/* - * Author: Constantin Musca - * Author: Brendan Le Foll - * Author: Thomas Ingleby - * Copyright (c) 2014-2016 Intel Corporation. - * - * 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. - */ - -#include -#include -#include -#include "mraa_internal.h" -#include "gpio.h" -#include "version.h" -#include - -BPeripheralManagerClient *client = NULL; -char **gpios = NULL; -int gpios_count = 0; -char **i2c_busses = NULL; -int i2c_busses_count = 0; -char **spi_busses = NULL; -int spi_busses_count = 0; -char **uart_devices = NULL; -int uart_busses_count = 0; -mraa_lang_func_t* lang_func = NULL; - -const char* -mraa_get_version() -{ - return gVERSION; -} - -mraa_result_t -mraa_set_log_level(int level) -{ - syslog(LOG_WARNING, "mraa: function not implementedin PMRAA"); - return MRAA_ERROR_INVALID_PARAMETER; -} - -static void free_resources(char ***resources, int count) -{ - int i; - - if (*resources != NULL) { - for(i = 0; i < count; i++) { - free((*resources)[i]); - } - free(*resources); - } - - *resources = NULL; -} - -mraa_result_t -mraa_init() -{ - if (client != NULL) { - BPeripheralManagerClient_delete(client); - } - - client = BPeripheralManagerClient_new(); - if (client == NULL) { - return MRAA_ERROR_PLATFORM_NOT_INITIALISED; - } - - gpios = BPeripheralManagerClient_listGpio(client, &gpios_count); - i2c_busses = BPeripheralManagerClient_listI2cBuses(client, &i2c_busses_count); - spi_busses = BPeripheralManagerClient_listSpiBuses(client, &spi_busses_count); - uart_devices = BPeripheralManagerClient_listUartDevices(client, &uart_busses_count); - //lang_func - lang_func = (mraa_lang_func_t*) calloc(1, sizeof(mraa_lang_func_t)); - if (lang_func == NULL) { - return MRAA_ERROR_NO_RESOURCES; - } - - return MRAA_SUCCESS; -} - -void -mraa_deinit() -{ - free_resources(&uart_devices, uart_busses_count); - free_resources(&spi_busses, spi_busses_count); - free_resources(&i2c_busses, i2c_busses_count); - free_resources(&gpios, gpios_count); - - if (client != NULL) { - BPeripheralManagerClient_delete(client); - client = NULL; - } -} - - -mraa_platform_t -mraa_get_platform_type() -{ - syslog(LOG_WARNING, "mraa: function not implementedin PMRAA"); - return -1; -} - -int mraa_get_default_i2c_bus(uint8_t platform_offset) { - // return first bus available - return 0; -} - -unsigned int -mraa_adc_raw_bits() -{ - syslog(LOG_WARNING, "mraa: function not implementedin PMRAA"); - return 0; - -} - -unsigned int -mraa_adc_supported_bits() -{ - syslog(LOG_WARNING, "mraa: function not implementedin PMRAA"); - return 0; -} - -int -mraa_set_priority(const int priority) -{ - syslog(LOG_WARNING, "mraa: function not implementedin PMRAA"); - return -1; -} - -const char* -mraa_get_platform_name() -{ - syslog(LOG_WARNING, "mraa: function not implementedin PMRAA"); - return NULL; -} - -const char* -mraa_get_platform_version(int platform_offset) -{ - syslog(LOG_WARNING, "mraa: function not implementedin PMRAA"); - return NULL; -} - -unsigned int -mraa_get_pin_count() -{ - syslog(LOG_WARNING, "mraa: function not implementedin PMRAA"); - return 0; -} - -int -mraa_get_i2c_bus_count() -{ - syslog(LOG_WARNING, "mraa: function not implementedin PMRAA"); - return -1; -} - -int -mraa_get_i2c_bus_id(int i2c_bus) -{ - syslog(LOG_WARNING, "mraa: function not implementedin PMRAA"); - return -1; -} - -mraa_boolean_t -mraa_pin_mode_test(int pin, mraa_pinmodes_t mode) -{ - syslog(LOG_WARNING, "mraa: function not implementedin PMRAA"); - return 0; -} - -char* -mraa_get_pin_name(int pin) -{ - syslog(LOG_WARNING, "mraa: function not implementedin PMRAA"); - return 0; -} - -mraa_boolean_t -mraa_has_sub_platform() -{ - syslog(LOG_WARNING, "mraa: function not implementedin PMRAA"); - return 0; -} - -mraa_boolean_t -mraa_is_sub_platform_id(int pin_or_bus) -{ - syslog(LOG_WARNING, "mraa: function not implementedin PMRAA"); - return 0; -} - -int -mraa_get_sub_platform_id(int pin_or_bus) -{ - syslog(LOG_WARNING, "mraa: function not implementedin PMRAA"); - return -1; -} - -int -mraa_get_sub_platform_index(int pin_or_bus) -{ - syslog(LOG_WARNING, "mraa: function not implementedin PMRAA"); - return -1; -} - -mraa_result_t -mraa_add_subplatform(mraa_platform_t subplatformtype, const char* uart_dev) -{ - syslog(LOG_WARNING, "mraa: function not implementedin PMRAA"); - return MRAA_ERROR_INVALID_PARAMETER; -} - -mraa_result_t -mraa_remove_subplatform(mraa_platform_t subplatformtype) -{ - return MRAA_ERROR_INVALID_PARAMETER; -} - -void -mraa_result_print(mraa_result_t result) -{ - syslog(LOG_WARNING, "mraa: function not implementedin PMRAA"); - fprintf(stdout, "MRAA: Unrecognised error."); -} - -void -mraa_to_upper(char* s) -{ - char* t = s; - for (; *t; ++t) { - *t = toupper(*t); - } -} - -mraa_result_t -mraa_atoi(char* intStr, int* value) -{ - char* end; - // here 10 determines the number base in which strol is to work - long val = strtol(intStr, &end, 10); - if (*end != '\0' || errno == ERANGE || end == intStr || val > INT_MAX || val < INT_MIN) { - *value = 0; - return MRAA_ERROR_UNSPECIFIED; - } - *value = (int) val; - return MRAA_SUCCESS; -} - -void* -mraa_init_io(const char* desc) -{ - void* dev; - int rc; - const char* delim = "-"; - int length = 0; - // 256 denotes the maximum size of our buffer - // 8 denotes the maximum size of our type rounded to the nearest power of 2 - // max size is 4 + 1 for the \0 = 5 rounded to 8 - char buffer[256] = { 0 }, type[8] = { 0 }; - char *token = 0, *str = 0; - if (desc == NULL) { - return NULL; - } - length = strlen(desc); - // Check to see the length is less than or equal to 255 which means - // byte 256 is supposed to be \0 - if (length > 255 || length == 0) { - return NULL; - } - strncpy(buffer, desc, length); - - str = buffer; - token = strsep(&str, delim); - length = strlen(token); - // Check to see they haven't given us a type whose length is greater than the - // largest type we know about - if (length > 4) { - syslog(LOG_ERR, "mraa_init_io: An invalid IO type was provided"); - return NULL; - } - strncpy(type, token, length); - mraa_to_upper(type); - token = strsep(&str, delim); - // Check that they've given us more information than just the type - if (token == NULL) { - syslog(LOG_ERR, "mraa_init_io: Missing information after type"); - return NULL; - } - - if (strncmp(type, "GPIO", 4) == 0) { - if ((dev = calloc(sizeof(struct _gpio), 1)) == NULL) { - syslog(LOG_ERR, "mraa_init_io: cannot allocate memory for GPIO %s", token); - return NULL; - } - - rc = BPeripheralManagerClient_openGpio(client, token, &((mraa_gpio_context)dev)->bgpio); - if (rc != 0) { - syslog(LOG_ERR, "mraa_init_io: cannot open GPIO %s", token); - free(dev); - return NULL; - } - - return dev; - } else if (strncmp(type, "I2C", 3) == 0) { - dev = calloc(1, sizeof(struct _i2c)); - if (dev == NULL) { - syslog(LOG_ERR, "mraa_init_io: cannot allocate memory for I2C %s", token); - return NULL; - } - - strncpy(((mraa_i2c_context)dev)->bus_name, token, MAX_I2C_BUS_NAME - 1); - return dev; - } else if (strncmp(type, "SPI", 3) == 0) { - dev = calloc(1, sizeof(struct _spi)); - if (dev == NULL) { - syslog(LOG_ERR, "mraa_init_io: cannot allocate memory for SPI %s", token); - return NULL; - } - - rc = BPeripheralManagerClient_openSpiDevice(client, token, &((mraa_spi_context)dev)->bspi); - if (rc != 0) { - syslog(LOG_ERR, "mraa_init_io: cannot open SPI %s", token); - free(dev); - return NULL; - } - - return dev; - } else if (strncmp(type, "UART", 4) == 0) { - dev = calloc(1, sizeof(struct _uart)); - if (dev == NULL) { - syslog(LOG_ERR, "mraa_init_io: cannot allocate memory for UART %s", token); - return NULL; - } - - rc = BPeripheralManagerClient_openUartDevice(client, token, &((mraa_uart_context)dev)->buart); - if (rc != 0) { - syslog(LOG_ERR, "mraa_init_io: cannot open UART %s", token); - free(dev); - return NULL; - } - } - - syslog(LOG_ERR, "mraa_init_io: Invalid IO type given."); - return NULL; -} - -#ifndef JSONPLAT -mraa_result_t -mraa_init_json_platform(const char* desc) -{ - return MRAA_ERROR_FEATURE_NOT_SUPPORTED; -} -#endif diff --git a/src/peripheralman/peripheralman_aio.c b/src/peripheralman/peripheralman_aio.c deleted file mode 100644 index ff1b3b0..0000000 --- a/src/peripheralman/peripheralman_aio.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Author: Sanrio Alvares - * Copyright (c) 2016 Intel Corporation. - * - * 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. - */ - -#include "aio.h" -#include "mraa_internal.h" -#include - -mraa_aio_context -mraa_aio_init(unsigned int aio) -{ - return NULL; -} - -unsigned int -mraa_aio_read(mraa_aio_context dev) -{ - return -1; -} - -float -mraa_aio_read_float(mraa_aio_context dev) -{ - return -1; -} - -mraa_result_t -mraa_aio_close(mraa_aio_context dev) -{ - return -1; -} - -mraa_result_t -mraa_aio_set_bit(mraa_aio_context dev, int bits) -{ - return -1; -} - -int -mraa_aio_get_bit(mraa_aio_context dev) -{ - return -1; -} - diff --git a/src/peripheralman/peripheralman_gpio.c b/src/peripheralman/peripheralman_gpio.c deleted file mode 100644 index 90afcf3..0000000 --- a/src/peripheralman/peripheralman_gpio.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Author: Constantin Musca - * Brendan Le Foll - * Copyright (c) 2016 Intel Corporation. - * - * 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. - */ - -#include -#include -#include - -// API -#include "mraa/gpio.h" - -// mraa internals -#include "mraa_internal.h" - -extern BPeripheralManagerClient *client; -extern char **gpios; -extern int gpios_count; - -static mraa_result_t -mraa_pman_gpio_init_internal_replace(mraa_gpio_context dev, int pin) -{ - rc = BPeripheralManagerClient_openGpio(client, gpios[pin], &dev->bgpio); - if (rc != 0) { - syslog(LOG_ERROR, "peripheralmanager: Failed to init gpio"); - return MRAA_ERROR_INVALID_HANDLE; - } - dev->pin = pin; - dev->phy_pin = pin; - - return dev; -} - -static mraa_result_t -mraa_pman_gpio_close_replace(mraa_gpio_context dev) -{ - if (dev->bgpio != NULL) { - BGpio_delete(dev->bgpio); - } - - free(dev); - return MRAA_SUCCESS; -} - -static mraa_result_t -mraa_pman_gpio_dir(mraa_gpio_context dev, mraa_gpio_dir_t dir) -{ - int rc; - - if (dev->bgpio == NULL) { - syslog(LOG_ERROR, "peripheralman: Invalid internal gpio handle"); - return MRAA_ERROR_INVALID_HANDLE; - } - - switch (dir) { - case MRAA_GPIO_IN: - rc = BGpio_setDirection(dev->bgpio, DIRECTION_IN); - break; - case MRAA_GPIO_OUT: - case MRAA_GPIO_OUT_HIGH: - rc = BGpio_setDirection(dev->bgpio, DIRECTION_OUT_INITIALLY_HIGH); - break; - case MRAA_GPIO_OUT_LOW: - rc = BGpio_setDirection(dev->bgpio, DIRECTION_OUT_INITIALLY_LOW); - break; - } - if (rc != 0) { - syslog(LOG_ERROR, "peripheralman: Failed to switch direction"); - return MRAA_ERROR_INVALID_HANDLE; - } - - return MRAA_SUCCESS; -} - -static mraa_result_t -mraa_pman_gpio_read_dir_replace(mraa_gpio_context dev, mraa_gpio_dir_t *dir) -{ - syslog(LOG_WARNING, "peripheralman: mraa_gpio_read_dir() dunction not implemented on this backend"); - return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED; -} - -static mraa_result_t -mraa_pman_gpio_write_replace(mraa_gpio_context dev, int val) -{ - int rc; - - if (dev->bgpio == NULL) { - syslog(LOG_ERROR, "peripheralman: Invalid internal gpio handle"); - return MRAA_ERROR_INVALID_HANDLE; - } - - rc = BGpio_setValue(dev->bgpio, val); - if (rc != 0) { - return MRAA_ERROR_INVALID_RESOURCE; - } - - return MRAA_SUCCESS; -} - -static int -mraa_pman_gpio_read_replace(mraa_gpio_context dev) -{ - int rc, val; - - if (dev->bgpio == NULL) { - syslog(LOG_ERROR, "peripheralman: Invalid internal gpio handle"); - return -1; - } - - rc = BGpio_getValue(dev->bgpio, &val); - if (rc != 0) { - syslog(LOG_ERROR, "peripheralman: Unable to read internal gpio") - return -1; - } - - return val; -} - -static mraa_result_t -mraa_pman_gpio_edge_mode_replace(mraa_gpio_context dev, mraa_gpio_edge_t mode) -{ - int rc; - - if (dev->bgpio == NULL) { - return MRAA_ERROR_INVALID_HANDLE; - } - - switch (mode) { - case MRAA_GPIO_EDGE_BOTH: - rc = BGpio_setEdgeTriggerType(dev->bgpio, BOTH_EDGE); - break; - case MRAA_GPIO_EDGE_FALLING: - rc = BGpio_setEdgeTriggerType(dev->bgpio, FALLING_EDGE); - break; - case MRAA_GPIO_EDGE_RISING: - rc = BGpio_setEdgeTriggerType(dev->bgpio, RISING_EDGE); - break; - case MRAA_GPIO_EDGE_NONE: - rc = BGpio_setEdgeTriggerType(dev->bgpio, NONE_EDGE); - break; - } - if (rc != 0) { - return MRAA_ERROR_INVALID_HANDLE; - } - - return MRAA_SUCCESS; -}; - -static mraa_result_t -mraa_pman_gpio_isr_replace(mraa_gpio_context dev, mraa_gpio_edge_t edge, void (*fptr)(void*), void* args) -{ - return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED; -} - -static mraa_result_t -mraa_pman_gpio_mode_replace(mraa_gpio_context dev, mraa_gpio_mode_t mode) -{ - return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED; -} - diff --git a/src/peripheralman/peripheralman_i2c.c b/src/peripheralman/peripheralman_i2c.c deleted file mode 100644 index ddad35a..0000000 --- a/src/peripheralman/peripheralman_i2c.c +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Author: Constantin Musca - * Copyright (c) 2016 Intel Corporation. - * - * 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. - */ - -#include "i2c.h" -#include "mraa_internal.h" -#include - -extern BPeripheralManagerClient *client; -extern char **i2c_busses; -extern int i2c_busses_count; - -mraa_i2c_context mraa_i2c_init_raw(unsigned int bus) -{ - mraa_i2c_context dev; - - if ((int)bus > i2c_busses_count) { - return NULL; - } - - dev = (mraa_i2c_context) calloc(1, sizeof(struct _i2c)); - if (dev == NULL) { - syslog(LOG_CRIT, "i2c: Failed to allocate memory for context"); - return NULL; - } - - dev->busnum = bus; - return dev; -} - -mraa_i2c_context mraa_i2c_init(int bus) -{ - return mraa_i2c_init_raw(bus); -} - - -mraa_result_t -mraa_i2c_frequency(mraa_i2c_context dev, mraa_i2c_mode_t mode) -{ - return MRAA_ERROR_FEATURE_NOT_SUPPORTED; -} - -int -mraa_i2c_read(mraa_i2c_context dev, uint8_t* data, int length) -{ - int rc; - - if (dev->bi2c == NULL) { - return 0; - } - - rc = BI2cDevice_read(dev->bi2c, data, length); - - return rc; -} - -int -mraa_i2c_read_byte(mraa_i2c_context dev) -{ - int rc; - uint8_t val; - - if (dev->bi2c == NULL) { - return 0; - } - - rc = BI2cDevice_read(dev->bi2c, &val, 1); - if (rc != 0 ) { - return rc; - } - - return val; -} - -int -mraa_i2c_read_byte_data(mraa_i2c_context dev, uint8_t command) -{ - int rc; - uint8_t val; - - if (dev->bi2c == NULL) { - return 0; - } - - rc = BI2cDevice_readRegByte(dev->bi2c, command, &val); - if (rc != 0) { - return 0; - } - - return val; -} - -int -mraa_i2c_read_word_data(mraa_i2c_context dev, uint8_t command) -{ - int rc; - uint16_t val; - - if (dev->bi2c == NULL) { - return 0; - } - - rc = BI2cDevice_readRegWord(dev->bi2c, command, &val); - if (rc != 0) { - return 0; - } - - return val; -} - -int -mraa_i2c_read_bytes_data(mraa_i2c_context dev, uint8_t command, uint8_t* data, int length) -{ - int rc; - - if (dev->bi2c == NULL) { - return -1; - } - - rc = BI2cDevice_readRegBuffer(dev->bi2c, command, data, length); - - return rc; -} - -mraa_result_t -mraa_i2c_write(mraa_i2c_context dev, const uint8_t* data, int length) -{ - int rc; - - if (dev->bi2c == NULL) { - return MRAA_ERROR_INVALID_HANDLE; - } - - rc = BI2cDevice_write(dev->bi2c, data, length); - if (rc != 0) { - return MRAA_ERROR_INVALID_RESOURCE; - } - - return MRAA_SUCCESS; -} - -mraa_result_t -mraa_i2c_write_byte(mraa_i2c_context dev, const uint8_t data) -{ - return mraa_i2c_write(dev, &data, 1); -} - -mraa_result_t -mraa_i2c_write_byte_data(mraa_i2c_context dev, const uint8_t data, const uint8_t command) -{ - int rc; - - if (dev->bi2c == NULL) { - return MRAA_ERROR_INVALID_HANDLE; - } - - rc = BI2cDevice_writeRegByte(dev->bi2c, command, data); - if (rc != 0) { - return MRAA_ERROR_INVALID_RESOURCE; - } - - return MRAA_SUCCESS; -} - -mraa_result_t -mraa_i2c_write_word_data(mraa_i2c_context dev, const uint16_t data, const uint8_t command) -{ - int rc; - - if (dev->bi2c == NULL) { - return MRAA_ERROR_INVALID_HANDLE; - } - - rc = BI2cDevice_writeRegWord(dev->bi2c, command, data); - if (rc != 0) { - return MRAA_ERROR_INVALID_RESOURCE; - } - - return MRAA_SUCCESS; -} - -mraa_result_t -mraa_i2c_address(mraa_i2c_context dev, uint8_t addr) -{ - int rc; - - if (dev == NULL || dev->busnum > (int)i2c_busses_count) { - return MRAA_ERROR_INVALID_HANDLE; - } - - dev->addr = (int) addr; - - if (strlen(dev->bus_name) > 0) { - rc = BPeripheralManagerClient_openI2cDevice(client, - dev->bus_name, addr, &dev->bi2c); - } else { - rc = BPeripheralManagerClient_openI2cDevice(client, - i2c_busses[dev->busnum], addr, &dev->bi2c); - } - if (rc != 0) { - return MRAA_ERROR_INVALID_RESOURCE; - } - - return MRAA_SUCCESS; -} - - -mraa_result_t -mraa_i2c_stop(mraa_i2c_context dev) -{ - if (dev->bi2c != NULL) { - BI2cDevice_delete(dev->bi2c); - dev->bi2c = NULL; - } - - free(dev); - return MRAA_SUCCESS; -} diff --git a/src/peripheralman/peripheralman_pwm.c b/src/peripheralman/peripheralman_pwm.c deleted file mode 100644 index 441aedf..0000000 --- a/src/peripheralman/peripheralman_pwm.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Author: Sanrio Alvares - * Copyright (c) 2016 Intel Corporation. - * - * 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. - */ - -#include "pwm.h" -#include "mraa_internal.h" -#include - -mraa_pwm_context -mraa_pwm_init(int pin) -{ - return NULL; -} - -mraa_pwm_context -mraa_pwm_init_raw(int chipid, int pin) -{ - return NULL; -} - -mraa_result_t -mraa_pwm_write(mraa_pwm_context dev, float percentage) -{ - return -1; -} - -float -mraa_pwm_read(mraa_pwm_context dev) -{ - return -1; -} - -mraa_result_t -mraa_pwm_period(mraa_pwm_context dev, float seconds) -{ - return -1; -} - -mraa_result_t -mraa_pwm_period_ms(mraa_pwm_context dev, int ms) -{ - return -1; -} - -mraa_result_t -mraa_pwm_period_us(mraa_pwm_context dev, int us) -{ - return -1; -} - -mraa_result_t -mraa_pwm_pulsewidth(mraa_pwm_context dev, float seconds) -{ - return -1; -} - -mraa_result_t -mraa_pwm_pulsewidth_ms(mraa_pwm_context dev, int ms) -{ - return -1; -} - -mraa_result_t -mraa_pwm_pulsewidth_us(mraa_pwm_context dev, int us) -{ - return -1; -} - -mraa_result_t -mraa_pwm_enable(mraa_pwm_context dev, int enable) -{ - return -1; -} - -mraa_result_t -mraa_pwm_owner(mraa_pwm_context dev, mraa_boolean_t owner) -{ - return -1; -} - -mraa_result_t -mraa_pwm_close(mraa_pwm_context dev) -{ - return -1; -} - -int -mraa_pwm_get_max_period(mraa_pwm_context dev) -{ - return -1; -} - -int -mraa_pwm_get_min_period(mraa_pwm_context dev) -{ - return -1; -} diff --git a/src/peripheralman/peripheralman_spi.c b/src/peripheralman/peripheralman_spi.c deleted file mode 100644 index 14252a1..0000000 --- a/src/peripheralman/peripheralman_spi.c +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Author: Constantin Musca - * Copyright (c) 2016 Intel Corporation. - * - * 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. - */ - -#include "spi.h" -#include "mraa_internal.h" - -extern BPeripheralManagerClient *client; -extern char **spi_busses; -extern int spi_busses_count; - -mraa_spi_context -mraa_spi_init(int bus) -{ - int rc; - mraa_spi_context dev; - - if (bus > spi_busses_count) { - return NULL; - } - - dev = (mraa_spi_context) calloc(1, sizeof(struct _spi)); - if (dev == NULL) { - return NULL; - } - - rc = BPeripheralManagerClient_openSpiDevice(client, spi_busses[bus], &dev->bspi); - if (rc != 0) { - free(dev); - return NULL; - } - - return dev; -} - -mraa_spi_context -mraa_spi_init_raw(unsigned int bus, unsigned int cs) -{ - return NULL; -} - -mraa_result_t -mraa_spi_mode(mraa_spi_context dev, mraa_spi_mode_t mode) -{ - int rc; - - if (dev->bspi == NULL) { - return MRAA_ERROR_INVALID_RESOURCE; - } - - switch (mode) { - case MRAA_SPI_MODE0: - rc = BSpiDevice_setMode(dev->bspi, SPI_MODE0); - break; - case MRAA_SPI_MODE1: - rc = BSpiDevice_setMode(dev->bspi, SPI_MODE1); - break; - case MRAA_SPI_MODE2: - rc = BSpiDevice_setMode(dev->bspi, SPI_MODE2); - break; - case MRAA_SPI_MODE3: - rc = BSpiDevice_setMode(dev->bspi, SPI_MODE3); - break; - default: - rc = BSpiDevice_setMode(dev->bspi, SPI_MODE0); - break; - } - if (rc != 0) { - return MRAA_ERROR_INVALID_RESOURCE; - } - - dev->mode = mode; - - return MRAA_SUCCESS; -} - -mraa_result_t -mraa_spi_frequency(mraa_spi_context dev, int hz) -{ - int rc; - - if (dev->bspi == NULL) { - return MRAA_ERROR_INVALID_RESOURCE; - } - - rc = BSpiDevice_setFrequency(dev->bspi, hz); - if (rc != 0) { - return MRAA_ERROR_INVALID_RESOURCE; - } - - dev->clock = hz; - - return MRAA_SUCCESS; -} - -mraa_result_t -mraa_spi_lsbmode(mraa_spi_context dev, mraa_boolean_t lsb) -{ - int rc; - - if (dev->bspi == NULL) { - return MRAA_ERROR_INVALID_RESOURCE; - } - - if (lsb) { - rc = BSpiDevice_setBitJustification(dev->bspi, SPI_LSB_FIRST); - } else { - rc = BSpiDevice_setBitJustification(dev->bspi, SPI_MSB_FIRST); - } - if (rc != 0) { - return MRAA_ERROR_INVALID_RESOURCE; - } - - dev->lsb = lsb; - return MRAA_SUCCESS; -} - -mraa_result_t -mraa_spi_bit_per_word(mraa_spi_context dev, unsigned int bits) -{ - if (dev->bspi == NULL) { - return MRAA_ERROR_INVALID_RESOURCE; - } - - if (BSpiDevice_setBitsPerWord(dev->bspi, bits) != 0) { - return MRAA_ERROR_INVALID_RESOURCE; - } - - return MRAA_SUCCESS; -} - -int -mraa_spi_write(mraa_spi_context dev, uint8_t data) -{ - int rc; - uint8_t recv = 0; - - if (dev->bspi == NULL) { - return -1; - } - - rc = BSpiDevice_transfer(dev->bspi, &data, &recv, 1); - if (rc != 0) { - return -1; - } - - return (int) recv; -} - -int -mraa_spi_write_word(mraa_spi_context dev, uint16_t data) -{ - int rc; - uint16_t recv = 0; - - if (dev->bspi == NULL) { - return -1; - } - - rc = BSpiDevice_transfer(dev->bspi, &data, &recv, 2); - if (rc != 0) { - return -1; - } - - return (int) recv; -} - -mraa_result_t -mraa_spi_transfer_buf(mraa_spi_context dev, uint8_t* data, uint8_t* rxbuf, int length) -{ - int rc; - - if (dev->bspi == NULL) { - return MRAA_ERROR_INVALID_RESOURCE; - } - - rc = BSpiDevice_transfer(dev->bspi, data, rxbuf, length); - if (rc != 0) { - return MRAA_ERROR_INVALID_RESOURCE; - } - - return MRAA_SUCCESS; -} - -mraa_result_t -mraa_spi_transfer_buf_word(mraa_spi_context dev, uint16_t* data, uint16_t* rxbuf, int length) -{ - int rc; - - if (dev->bspi == NULL) { - return MRAA_ERROR_INVALID_RESOURCE; - } - - // IS IT CORRECT ? - rc = BSpiDevice_transfer(dev->bspi, data, rxbuf, length * 2); - if (rc != 0) { - return MRAA_ERROR_INVALID_RESOURCE; - } - - return MRAA_SUCCESS; -} - -uint8_t* -mraa_spi_write_buf(mraa_spi_context dev, uint8_t* data, int length) -{ - uint8_t *recv = malloc(sizeof(uint8_t) * length); - - if (mraa_spi_transfer_buf(dev, data, recv, length) != MRAA_SUCCESS) { - free(recv); - return NULL; - } - return recv; -} - -uint16_t* -mraa_spi_write_buf_word(mraa_spi_context dev, uint16_t* data, int length) -{ - uint16_t *recv = malloc(sizeof(uint16_t) * length); - - if (mraa_spi_transfer_buf_word(dev, data, recv, length) != MRAA_SUCCESS) { - free(recv); - return NULL; - } - return recv; -} - -mraa_result_t -mraa_spi_stop(mraa_spi_context dev) -{ - if (dev->bspi != NULL) { - BSpiDevice_delete(dev->bspi); - dev->bspi = NULL; - } - - free(dev); - return MRAA_SUCCESS; -} diff --git a/src/peripheralman/peripheralman_uart.c b/src/peripheralman/peripheralman_uart.c deleted file mode 100644 index 2984e2b..0000000 --- a/src/peripheralman/peripheralman_uart.c +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Author: Sanrio Alvares - * Copyright (c) 2016 Intel Corporation. - * - * 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. - */ - -#include "uart.h" -#include "mraa_internal.h" -#include -#include - -extern BPeripheralManagerClient *client; -extern char **uart_devices; -extern int uart_busses_count; - -// do i need a speed(B9600) to int(9600) converter? - -mraa_uart_context -mraa_uart_init_raw(const char* path) -{ - return NULL; -} - -mraa_uart_context -mraa_uart_init(int index) -{ - int rc; - char device_name[10] = {'\0'}; - mraa_uart_context dev; - - if (index > uart_busses_count) { - return NULL; - } - - dev = (mraa_uart_context) calloc(1, sizeof(struct _uart)); - if (dev == NULL) { - return NULL; - } - - snprintf(device_name, sizeof(device_name), "UART%d", index); - - rc = BPeripheralManagerClient_openUartDevice(client, device_name, &dev->buart); - if (rc != 0) { - BUartDevice_delete(dev->buart); - free(dev); - return NULL; - } - - return dev; -} - -mraa_result_t -mraa_uart_flush(mraa_uart_context dev) -{ - return -1; -} - -mraa_result_t -mraa_uart_set_baudrate(mraa_uart_context dev, unsigned int baud) -{ - int rc; - - if (!dev) { - syslog(LOG_ERR, "uart: stop: context is NULL"); - return 0; - } - - rc = BUartDevice_setBaudrate(dev->buart, baud); - if (rc != 0) { - return 0; - } - - return MRAA_SUCCESS; -} - -int -mraa_uart_read(mraa_uart_context dev, char* buf, size_t length) -{ - int rc; - uint32_t bytes_read; - - if (dev->buart == NULL) { - return MRAA_ERROR_INVALID_HANDLE; - } - - rc = BUartDevice_read(dev->buart, buf, length, &bytes_read); - if (rc != 0) { - return MRAA_ERROR_INVALID_RESOURCE; - } - - return bytes_read; -} - -int -mraa_uart_write(mraa_uart_context dev, const char* buf, size_t length) -{ - int rc; - uint32_t bytes_written; - - if (dev->buart == NULL) { - return MRAA_ERROR_INVALID_HANDLE; - } - - rc = BUartDevice_write(dev->buart, buf, length, &bytes_written); - if (rc != 0) { - return MRAA_ERROR_INVALID_RESOURCE; - } - - return bytes_written; -} - -mraa_result_t -mraa_uart_set_mode(mraa_uart_context dev, int bytesize, mraa_uart_parity_t parity, int stopbits) -{ - return -1; -} - -mraa_result_t -mraa_uart_set_flowcontrol(mraa_uart_context dev, mraa_boolean_t xonxoff, mraa_boolean_t rtscts) -{ - return -1; -} - -mraa_result_t -mraa_uart_set_timeout(mraa_uart_context dev, int read, int write, int interchar) -{ - return -1; -} - -mraa_result_t -mraa_uart_set_non_blocking(mraa_uart_context dev, mraa_boolean_t nonblock) -{ - return -1; -} - -const char* -mraa_uart_get_dev_path(mraa_uart_context dev) -{ - return NULL; -} - -mraa_result_t -mraa_uart_stop(mraa_uart_context dev) -{ - return -1; -} - -mraa_boolean_t -mraa_uart_data_available(mraa_uart_context dev, unsigned int millis) -{ - return 0; -}