70 lines
1.5 KiB
C
70 lines
1.5 KiB
C
//#define PICO
|
|
|
|
#ifndef GPIO_H
|
|
#define GPIO_H
|
|
|
|
#ifdef PICO
|
|
#include <pico/printf.h>
|
|
#include <pico/stdlib.h>
|
|
#include <hardware/pwm.h>
|
|
#include <FreeRTOS.h>
|
|
#include <semphr.h>
|
|
#include <task.h>
|
|
#else
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
#define PICO_DEFAULT_LED_PIN 0
|
|
#define GPIO_OUT 1
|
|
#define GPIO_IN 0
|
|
#endif
|
|
|
|
#define NB_GPIO 5
|
|
#define DEFAULT_WRAP_LEVEL 20
|
|
|
|
typedef struct gpio gpio;
|
|
struct gpio {
|
|
size_t pin;
|
|
size_t direction;
|
|
bool has_pwm;
|
|
uint16_t level;
|
|
bool state;
|
|
};
|
|
|
|
static gpio GPIO_DEFAULT_LED = (gpio) {
|
|
.pin = PICO_DEFAULT_LED_PIN, .direction = GPIO_OUT, .has_pwm = false, .level = 0, .state = false
|
|
};
|
|
|
|
static gpio GPIO_BUTTON = (gpio) {
|
|
.pin = 16, .direction = GPIO_IN, .has_pwm = false, .level = 0, .state = false
|
|
};
|
|
|
|
static gpio GPIO_BUZZER = (gpio) {
|
|
.pin = 15, .direction = GPIO_OUT, .has_pwm = false, .level = 0, .state = false
|
|
};
|
|
|
|
static gpio GPIO_ADC = (gpio) {
|
|
.pin = 26, .direction = GPIO_IN, .has_pwm = false, .level = 0, .state = false
|
|
};
|
|
|
|
static gpio GPIO_LED = (gpio) {
|
|
.pin = 20, .direction = GPIO_OUT, .has_pwm = true, .level = 0, .state = false
|
|
};
|
|
|
|
static gpio* GPIOS[NB_GPIO] = {&GPIO_DEFAULT_LED, &GPIO_BUTTON, &GPIO_BUZZER, &GPIO_ADC, &GPIO_LED};
|
|
|
|
void gpio_set_level(gpio *g, uint16_t level);
|
|
void gpio_set_state(gpio *g, bool state);
|
|
bool gpio_get_input(gpio* g);
|
|
double gpio_get_adc(void);
|
|
void gpio_onoff(gpio* g, uint32_t delay_ms, size_t times);
|
|
|
|
void init_gpio(void);
|
|
|
|
void _sleep_ms(size_t value);
|
|
void _sleep_us(size_t value);
|
|
|
|
#endif |