kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Added IO class for dealing with basic IO
rodzic
5afd816197
commit
dda775c85e
|
@ -1,6 +1,7 @@
|
|||
add_subdirectory(analog)
|
||||
add_subdirectory(analogmux)
|
||||
add_subdirectory(esp32spi)
|
||||
add_subdirectory(io)
|
||||
add_subdirectory(ioexpander)
|
||||
add_subdirectory(ltp305)
|
||||
add_subdirectory(ltr559)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
include(io.cmake)
|
|
@ -0,0 +1,11 @@
|
|||
set(DRIVER_NAME io)
|
||||
add_library(${DRIVER_NAME} INTERFACE)
|
||||
|
||||
target_sources(${DRIVER_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/${DRIVER_NAME}.cpp
|
||||
)
|
||||
|
||||
target_include_directories(${DRIVER_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
# Pull in pico libraries that we need
|
||||
target_link_libraries(${DRIVER_NAME} INTERFACE pico_stdlib)
|
|
@ -0,0 +1,48 @@
|
|||
#include "io.hpp"
|
||||
|
||||
namespace pimoroni {
|
||||
IO::IO(uint pin) :
|
||||
pin(pin) {
|
||||
gpio_init(pin);
|
||||
};
|
||||
|
||||
IO::IO(uint pin, bool out, bool pull_up, bool pull_down) :
|
||||
pin(pin) {
|
||||
gpio_init(pin);
|
||||
direction(out, pull_up, pull_down);
|
||||
};
|
||||
|
||||
bool IO::direction() {
|
||||
return gpio_is_dir_out(pin);
|
||||
}
|
||||
|
||||
void IO::direction(bool out, bool pull_up, bool pull_down) {
|
||||
gpio_set_dir(pin, out);
|
||||
gpio_set_pulls(pin, pull_up, pull_down);
|
||||
}
|
||||
|
||||
void IO::to_output(bool val) {
|
||||
gpio_set_pulls(pin, false, false);
|
||||
gpio_set_dir(pin, GPIO_OUT);
|
||||
gpio_put(pin, val);
|
||||
}
|
||||
|
||||
void IO::to_input(bool pull_up, bool pull_down) {
|
||||
gpio_set_dir(pin, GPIO_IN);
|
||||
gpio_set_pulls(pin, pull_up, pull_down);
|
||||
}
|
||||
|
||||
bool IO::value() {
|
||||
//if(gpio_is_dir_out(pin)) {
|
||||
// // NOTE: Documentation says this is just for debug use...
|
||||
// return gpio_get_out_level(pin);
|
||||
//}
|
||||
//else {
|
||||
return gpio_get(pin); // Cool! This seems to return the output state as well as the input state
|
||||
//}
|
||||
}
|
||||
|
||||
void IO::value(bool val) {
|
||||
gpio_put(pin, val);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
namespace pimoroni {
|
||||
|
||||
class IO {
|
||||
public:
|
||||
IO(uint pin);
|
||||
IO(uint pin, bool out, bool pull_up = false, bool pull_down = false);
|
||||
bool direction();
|
||||
void direction(bool out, bool pull_up = false, bool pull_down = false);
|
||||
void to_output(bool val);
|
||||
void to_input(bool pull_up = false, bool pull_down = false);
|
||||
bool value();
|
||||
void value(bool val);
|
||||
private:
|
||||
uint pin;
|
||||
};
|
||||
|
||||
}
|
|
@ -38,7 +38,7 @@ namespace pimoroni {
|
|||
ADC_ANY = 3
|
||||
};
|
||||
|
||||
enum IO {
|
||||
enum IOState {
|
||||
LOW = false,
|
||||
HIGH = true
|
||||
};
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "../../errors.hpp"
|
||||
#include "apa102.hpp"
|
||||
#include "ws2812.hpp"
|
||||
#include "io.hpp"
|
||||
|
||||
using namespace plasma;
|
||||
|
||||
|
@ -40,8 +41,9 @@ namespace pimoroni {
|
|||
float __count_avg;
|
||||
|
||||
WS2812* led_strip;
|
||||
uint __power_good;
|
||||
uint __power_en;
|
||||
APA102* apa_strip;
|
||||
IO* __power_good_io;
|
||||
IO* __power_en_io;
|
||||
|
||||
|
||||
|
||||
|
@ -49,7 +51,10 @@ namespace pimoroni {
|
|||
YukonModule(),
|
||||
halt_on_not_pgood(halt_on_not_pgood),
|
||||
__last_pgood(false),
|
||||
led_strip(nullptr) { //TODO strip_type, num_pixels, brightness=1.0, halt_on_not_pgood=False):
|
||||
led_strip(nullptr),
|
||||
apa_strip(nullptr),
|
||||
__power_good_io(nullptr),
|
||||
__power_en_io(nullptr) { //TODO strip_type, num_pixels, brightness=1.0, halt_on_not_pgood=False):
|
||||
//self.__strip_type = strip_type
|
||||
//if self.__strip_type == self.NEOPIXEL:
|
||||
// self.NAME += " (NeoPixel)"
|
||||
|
@ -62,6 +67,9 @@ namespace pimoroni {
|
|||
|
||||
~LEDStripModule() {
|
||||
delete(led_strip);
|
||||
delete(apa_strip);
|
||||
delete(__power_good_io);
|
||||
delete(__power_en_io);
|
||||
}
|
||||
|
||||
virtual void initialise(const SLOT& slot, SlotAccessor& accessor) {
|
||||
|
@ -81,13 +89,9 @@ namespace pimoroni {
|
|||
led_strip->set_hsv(i, hue, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
__power_good = slot.FAST1;
|
||||
__power_en = slot.FAST2;
|
||||
|
||||
// Create the power control pin objects
|
||||
gpio_init(__power_good); // self.__power_good = DigitalInOut(slot.FAST1)
|
||||
gpio_init(__power_en); // self.__power_en = DigitalInOut(slot.FAST2)
|
||||
|
||||
__power_good_io = new IO(slot.FAST1);
|
||||
__power_en_io = new IO(slot.FAST2);
|
||||
|
||||
// Configure strip and power pins
|
||||
configure();
|
||||
|
@ -97,41 +101,36 @@ namespace pimoroni {
|
|||
}
|
||||
|
||||
virtual void configure() {
|
||||
//self.__power_en.switch_to_output(False)
|
||||
gpio_set_function(__power_en, GPIO_FUNC_SIO);
|
||||
gpio_set_dir(__power_en, GPIO_OUT);
|
||||
gpio_put(__power_en, false);
|
||||
|
||||
//self.__power_good.switch_to_input(Pull.UP)
|
||||
gpio_set_function(__power_good, GPIO_FUNC_SIO);
|
||||
gpio_set_dir(__power_good, GPIO_IN);
|
||||
gpio_set_pulls(__power_good, true, false);
|
||||
printf(("LED Strip Configured, apparently: " + std::to_string(__power_en) + "\n").c_str());
|
||||
__power_en_io->to_output(false);
|
||||
__power_good_io->to_input(true, false);
|
||||
}
|
||||
|
||||
void enable() {
|
||||
if(!is_initialised()) {
|
||||
throw std::runtime_error("Module not initialised\n");
|
||||
}
|
||||
gpio_put(__power_en, true); //self.__power_en.value = True
|
||||
|
||||
printf(("LED Strip Enabled, apparently: " + std::to_string(__power_en) + "\n").c_str());
|
||||
__power_en_io->value(true);
|
||||
}
|
||||
|
||||
void disable() {
|
||||
if(!is_initialised()) {
|
||||
throw std::runtime_error("Module not initialised\n");
|
||||
}
|
||||
gpio_put(__power_en, false); //self.__power_en.value = False
|
||||
__power_en_io->value(false);
|
||||
}
|
||||
|
||||
bool is_enabled() {
|
||||
// Documentation has note that this is just for debug use!
|
||||
return gpio_get_out_level(__power_en); //return self.__power_en.value
|
||||
if(!is_initialised()) {
|
||||
throw std::runtime_error("Module not initialised\n");
|
||||
}
|
||||
return __power_en_io->value();
|
||||
}
|
||||
|
||||
bool read_power_good() {
|
||||
return gpio_get(__power_good); //return self.__power_en.value
|
||||
if(!is_initialised()) {
|
||||
throw std::runtime_error("Module not initialised\n");
|
||||
}
|
||||
return __power_good_io->value();
|
||||
}
|
||||
|
||||
float read_temperature() {
|
||||
|
|
|
@ -17,4 +17,4 @@ target_sources(yukon INTERFACE
|
|||
target_include_directories(yukon INTERFACE ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
# Pull in pico libraries that we need
|
||||
target_link_libraries(yukon INTERFACE pico_stdlib pico_graphics tca9555 hardware_adc plasma)
|
||||
target_link_libraries(yukon INTERFACE pico_stdlib pico_graphics tca9555 hardware_adc io plasma)
|
||||
|
|
Ładowanie…
Reference in New Issue