kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Added wrapper functions for controlling Yukon slow IO
rodzic
6fabb0255d
commit
611153ce53
|
@ -0,0 +1 @@
|
|||
include(yukon_simple_enable.cmake)
|
|
@ -0,0 +1,13 @@
|
|||
set(OUTPUT_NAME yukon_simple_enable)
|
||||
add_executable(${OUTPUT_NAME} yukon_simple_enable.cpp)
|
||||
|
||||
target_link_libraries(${OUTPUT_NAME}
|
||||
pico_stdlib
|
||||
yukon
|
||||
)
|
||||
|
||||
# enable usb output, disable uart output (so it doesn't confuse any connected servos)
|
||||
pico_enable_stdio_usb(${OUTPUT_NAME} 1)
|
||||
pico_enable_stdio_uart(${OUTPUT_NAME} 0)
|
||||
|
||||
pico_add_extra_outputs(${OUTPUT_NAME})
|
|
@ -0,0 +1,32 @@
|
|||
#include "pico/stdlib.h"
|
||||
|
||||
#include "yukon.hpp"
|
||||
using namespace pimoroni;
|
||||
/*
|
||||
Demonstrates how to create a Servo object and control it.
|
||||
*/
|
||||
|
||||
// How many sweeps of the servo to perform
|
||||
const uint SWEEPS = 3;
|
||||
|
||||
// The number of discrete sweep steps
|
||||
const uint STEPS = 10;
|
||||
|
||||
// The time in milliseconds between each step of the sequence
|
||||
const uint STEPS_INTERVAL_MS = 500;
|
||||
|
||||
// How far from zero to move the servo when sweeping
|
||||
constexpr float SWEEP_EXTENT = 90.0f;
|
||||
|
||||
|
||||
Yukon y = Yukon();
|
||||
|
||||
|
||||
int main() {
|
||||
stdio_init_all();
|
||||
|
||||
// Initialise the servo
|
||||
y.init();
|
||||
|
||||
y.set_slow_output(Yukon::MAIN_EN, true);
|
||||
}
|
|
@ -126,4 +126,40 @@ namespace pimoroni {
|
|||
tca1.set_polarity_port(0x0000);
|
||||
tca1.set_config_port(0xFCE6);
|
||||
}
|
||||
|
||||
TCA9555& Yukon::get_tca_chip(uint chip) {
|
||||
assert(chip < NUM_EXPANDERS);
|
||||
return (chip == 0) ? tca0 : tca1;
|
||||
}
|
||||
|
||||
bool Yukon::get_slow_input(TCA gpio) {
|
||||
return get_tca_chip(gpio.CHIP).get_gpio_input(gpio.GPIO);
|
||||
}
|
||||
|
||||
bool Yukon::get_slow_output(TCA gpio) {
|
||||
return get_tca_chip(gpio.CHIP).get_gpio_output(gpio.GPIO);
|
||||
}
|
||||
|
||||
bool Yukon::get_slow_config(TCA gpio) {
|
||||
return get_tca_chip(gpio.CHIP).get_gpio_config(gpio.GPIO);
|
||||
}
|
||||
|
||||
bool Yukon::get_slow_polarity(TCA gpio) {
|
||||
return get_tca_chip(gpio.CHIP).get_gpio_polarity(gpio.GPIO);
|
||||
}
|
||||
|
||||
void Yukon::set_slow_output(TCA gpio, bool value) {
|
||||
get_tca_chip(gpio.CHIP).set_gpio_output(gpio.GPIO, value);
|
||||
}
|
||||
void Yukon::set_slow_config(TCA gpio, bool output) {
|
||||
get_tca_chip(gpio.CHIP).set_gpio_config(gpio.GPIO, output);
|
||||
}
|
||||
|
||||
void Yukon::set_slow_polarity(TCA gpio, bool polarity) {
|
||||
get_tca_chip(gpio.CHIP).set_gpio_polarity(gpio.GPIO, polarity);
|
||||
}
|
||||
|
||||
void Yukon::change_output_mask(uint8_t chip, uint16_t mask, uint16_t state) {
|
||||
get_tca_chip(chip).change_output_mask(mask, state);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,6 +72,8 @@ namespace pimoroni {
|
|||
TCA9555 tca0;
|
||||
TCA9555 tca1;
|
||||
|
||||
static const uint NUM_EXPANDERS = 2;
|
||||
|
||||
public:
|
||||
Yukon() :
|
||||
i2c(24, 25),
|
||||
|
@ -82,6 +84,21 @@ namespace pimoroni {
|
|||
|
||||
void init();
|
||||
void reset();
|
||||
|
||||
private:
|
||||
TCA9555& get_tca_chip(uint chip);
|
||||
|
||||
public:
|
||||
bool get_slow_input(TCA gpio);
|
||||
bool get_slow_output(TCA gpio);
|
||||
bool get_slow_config(TCA gpio);
|
||||
bool get_slow_polarity(TCA gpio);
|
||||
|
||||
void set_slow_output(TCA gpio, bool value);
|
||||
void set_slow_config(TCA gpio, bool output);
|
||||
void set_slow_polarity(TCA gpio, bool polarity);
|
||||
|
||||
void change_output_mask(uint8_t chip, uint16_t mask, uint16_t state);
|
||||
};
|
||||
|
||||
}
|
Ładowanie…
Reference in New Issue