-/* Copyright (C) 2012-2013 Czech Technical University in Prague
+/*
+ * hal.c
*
- * Authors:
- * - Michal Horn <hornmich@fel.cvut.cz>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : gpio.c
- *
- * Abstract:
- * This file contains gpio pin configuration functions.
- * Some additional function for setting and getting pin values, getting
- * descriptors etc. are defined in header file as inline functions.
- *
- * Each pin is defined by its descriptor defined in hal_gpio_platform_def. The descriptor can be obtained
- * by hal_gpio_get_pin_dsc by giving a pin name as an argument.
+ * Created on: 16.7.2015
+ * Author: michal
*/
#include "hal/hal.h"
+#include "drv/spi.h"
extern gioPORT_t *port_id_map[MAX_PORT_CNT];
extern pin_map_element_t pin_map[MAX_PIN_CNT];
+extern port_def_t port_definition[PORT_CNT];
+
+#define SPI_PORT_BUF_LEN 4
+/** Buffer for spi command to be sent */
+uint8_t spi_port_buf_tx[SPI_PORT_BUF_LEN];
+/** Buffer for spi response */
+uint8_t spi_port_buf_rx[SPI_PORT_BUF_LEN];
uint8_t hal_gpio_get_pin_cnt() {
return MAX_PIN_CNT;
{
return hal_gpio_pin_conf_set(pin_dsc, pin_dsc);
}
+
+
+uint32_t hal_gio_port_get_val(uint32_t *config, uint32_t num_val, uint32_t *values)
+{
+ uint32_t i;
+
+ for (i = 0; i < num_val; i++) {
+ values[i] = hal_gpio_pin_get_value(config[i]);
+ }
+ return 0;
+}
+
+uint32_t hal_gio_port_set_val(uint32_t *config, uint32_t num_val, const uint32_t *values)
+{
+ uint32_t i;
+
+ for (i = 0; i < num_val; i++) {
+ hal_gpio_pin_set_value(config[i], (values[i/8] >> i%8) & 0x1);
+ }
+ return 0;
+}
+
+const port_def_t *hal_port_get_definitions()
+{
+ return (const port_def_t *)port_definition;
+}
+
+port_desc_t *hal_port_get_dsc(const char *port_name, int len)
+{
+ uint32_t i;
+ const char *port_name_ptr;
+ char port_name_term[32];
+
+ if (len != -1) { // port name not terminated by '\0'
+ strncpy(port_name_term, port_name, len);
+ port_name_term[len] = '\0';
+ port_name_ptr = port_name_term;
+ }
+ else port_name_ptr = port_name;
+
+ for (i = 0; i < PORT_CNT; i++) {
+ if (strcmp(port_name_ptr, port_definition[i].name) == 0)
+ return port_definition[i].desc;
+ }
+ return NULL;
+}
+
+uint32_t hal_spi_port_transfer_command(uint32_t *config, uint32_t num_bytes, const uint32_t *commands)
+{
+ spi_drv_t *ifc;
+ int i;
+ uint32_t ret;
+
+ for (i = 0; i < num_bytes; i++)
+ spi_port_buf_tx[i] = commands[i];
+
+ ifc = spi_find_drv(NULL, config[0]);
+ if (ifc == NULL)
+ return 0;
+
+ if (!(ifc->flags & SPI_IFC_ON))
+ return 0;
+
+ spi_transfer(ifc, config[1], num_bytes, spi_port_buf_tx, spi_port_buf_rx);
+ ret = 0;
+ for (i = 0; i < num_bytes; i++)
+ ret |= spi_port_buf_rx[i] << i*8;
+ return ret;
+}