62 lines
1.3 KiB
C
62 lines
1.3 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 3
|
|
|
|
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* GPIOS[NB_GPIO] = {&GPIO_DEFAULT_LED, &GPIO_BUTTON, &GPIO_BUZZER};
|
|
|
|
void gpio_set_level(gpio *g, uint16_t level);
|
|
void gpio_set_state(gpio *g, bool state);
|
|
bool gpio_get_input(gpio* g);
|
|
|
|
void init_gpio(void);
|
|
|
|
void blink_failed(size_t pin, uint32_t delay_ms);
|
|
void blink_passed(size_t pin, uint32_t delay_ms, char* msg);
|
|
|
|
void _sleep_ms(size_t value);
|
|
void _sleep_us(size_t value);
|
|
|
|
#endif |