Skip to content
Snippets Groups Projects
Commit 539283d3 authored by Clément Foucher's avatar Clément Foucher
Browse files

Added missing comments for GPIO API.

Also:
- Improved constants declarations in GPIO API header,
- Corrected an unused variable defined in HRTIM driver.
parent 2f634f5f
No related branches found
No related tags found
No related merge requests found
/*
* Copyright (c) 2022 LAAS-CNRS
* Copyright (c) 2023 LAAS-CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
......@@ -19,7 +19,7 @@
/**
* @brief Owntech GPIO API
* @date 2022
* @date 2023
*
* @author Clément Foucher <clement.foucher@laas.fr>
*/
......@@ -34,6 +34,11 @@ const struct device* const GPIO_B = DEVICE_DT_GET(DT_NODELABEL(gpiob));
const struct device* const GPIO_C = DEVICE_DT_GET(DT_NODELABEL(gpioc));
const struct device* const GPIO_D = DEVICE_DT_GET(DT_NODELABEL(gpiod));
const gpio_flags_t INPUT = GPIO_INPUT;
const gpio_flags_t INPUT_PULLUP = GPIO_INPUT | GPIO_PULL_UP;
const gpio_flags_t OUTPUT = GPIO_OUTPUT;
void GpioApi::configurePin(pin_t pin, gpio_flags_t flags)
{
gpio_pin_t pin_number = this->getPinNumber(pin);
......
/*
* Copyright (c) 2022 LAAS-CNRS
* Copyright (c) 2022-2023 LAAS-CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
......@@ -19,7 +19,7 @@
/**
* @brief Owntech GPIO API
* @date 2022
* @date 2023
*
* @author Clément Foucher <clement.foucher@laas.fr>
*/
......@@ -34,31 +34,31 @@ extern const struct device* const GPIO_B;
extern const struct device* const GPIO_C;
extern const struct device* const GPIO_D;
const gpio_flags_t INPUT = GPIO_INPUT;
const gpio_flags_t INPUT_PULLUP = GPIO_INPUT | GPIO_PULL_UP;
const gpio_flags_t OUTPUT = GPIO_OUTPUT;
const uint8_t PA = 0x00;
const uint8_t PB = 0x10;
const uint8_t PC = 0x20;
const uint8_t PD = 0x30;
const uint8_t P1 = 0x0;
const uint8_t P2 = 0x1;
const uint8_t P3 = 0x2;
const uint8_t P4 = 0x3;
const uint8_t P5 = 0x4;
const uint8_t P6 = 0x5;
const uint8_t P7 = 0x6;
const uint8_t P8 = 0x7;
const uint8_t P9 = 0x8;
const uint8_t P10 = 0x9;
const uint8_t P11 = 0xA;
const uint8_t P12 = 0xB;
const uint8_t P13 = 0xC;
const uint8_t P14 = 0xD;
const uint8_t P15 = 0xE;
const uint8_t P16 = 0xF;
extern const gpio_flags_t INPUT;
extern const gpio_flags_t INPUT_PULLUP;
extern const gpio_flags_t OUTPUT;
static const uint8_t PA = 0x00;
static const uint8_t PB = 0x10;
static const uint8_t PC = 0x20;
static const uint8_t PD = 0x30;
static const uint8_t P1 = 0x0;
static const uint8_t P2 = 0x1;
static const uint8_t P3 = 0x2;
static const uint8_t P4 = 0x3;
static const uint8_t P5 = 0x4;
static const uint8_t P6 = 0x5;
static const uint8_t P7 = 0x6;
static const uint8_t P8 = 0x7;
static const uint8_t P9 = 0x8;
static const uint8_t P10 = 0x9;
static const uint8_t P11 = 0xA;
static const uint8_t P12 = 0xB;
static const uint8_t P13 = 0xC;
static const uint8_t P14 = 0xD;
static const uint8_t P15 = 0xE;
static const uint8_t P16 = 0xF;
typedef enum
{
......@@ -118,16 +118,68 @@ typedef enum
class GpioApi
{
public:
/**
* @brief Configure an I/O pin. This must be done
* prior to accessing any other function
* from this API on the pin.
*
* @param pin STM32-style name of the pin,
* e.g. PA1, PB10, etc. See pin_t type for
* the full list of existing pins on
* Spin board.
* @param flags Pin configuration flags.
* Authorized values:
* - INPUT
* - INPUT_PULLUP
* - OUTPUT
*/
void configurePin(pin_t pin, gpio_flags_t flags);
/**
* @brief Set the value of a pin configured as output to 1.
*
* @param pin STM32-style name of the pin.
*/
void setPin(pin_t pin);
/**
* @brief Reset the value of a pin configured as output to 0.
*
* @param pin STM32-style name of the pin.
*/
void resetPin(pin_t pin);
/**
* @brief Toggle the value of a pin configured as output:
* - if pin value is 1, it will be set to 0
* - if pin value is 0, it will be set to 1.
*
* @param pin STM32-style name of the pin.
*/
void togglePin(pin_t pin);
/**
* @brief Set the value of a pin configured as output
* to a given value.
*
* @param pin STM32-style name of the pin.
* @param value Value (0 or 1) to assign to the pin.
*/
void writePin(pin_t pin, uint8_t value);
/**
* @brief Get the current value of a pin configured as input.
*
* @param pin STM32-style name of the pin.
* @return Current value (0 or 1) of the pin.
*/
uint8_t readPin(pin_t pin);
private:
gpio_pin_t getPinNumber(pin_t pin);
const struct device* getGpioDevice(pin_t pin);
};
extern GpioApi gpio;
......
......@@ -41,7 +41,7 @@
#include "assert.h"
static const struct soc_gpio_pinctrl tim_pinctrl[] = ST_STM32_DT_INST_PINCTRL(0, 0);
//static const struct soc_gpio_pinctrl tim_pinctrl[] = ST_STM32_DT_INST_PINCTRL(0, 0);
static uint8_t _TU_num1(hrtim_tu_t tu) /* Return the number associated to the timing unit */
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment