picoco/buzzer/gpio.h

60 lines
1.2 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 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