-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from mutablelogic/dev
Added more picofuse code
- Loading branch information
Showing
76 changed files
with
3,839 additions
and
532 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
############################################################################## | ||
|
||
set(NAME "blink") | ||
|
||
add_executable(${NAME} | ||
common/main.c | ||
blink/run.c | ||
) | ||
target_include_directories(${NAME} PRIVATE | ||
${CMAKE_CURRENT_LIST_DIR}/../include | ||
) | ||
target_link_libraries(${NAME} picofuse) | ||
|
||
# enable usb output, disable uart output | ||
pico_enable_stdio_usb(${NAME} 1) | ||
pico_enable_stdio_uart(${NAME} 0) | ||
|
||
# create map/bin/hex/uf2 file etc. | ||
pico_add_extra_outputs(${NAME}) | ||
|
||
############################################################################## | ||
|
||
set(NAME "bme280_example") | ||
|
||
add_executable(${NAME} | ||
common/main.c | ||
bme280/run.c | ||
) | ||
target_include_directories(${NAME} PRIVATE | ||
${CMAKE_CURRENT_LIST_DIR}/../include | ||
) | ||
target_link_libraries(${NAME} | ||
picofuse | ||
bme280 | ||
) | ||
|
||
# enable usb output, disable uart output | ||
pico_enable_stdio_usb(${NAME} 1) | ||
pico_enable_stdio_uart(${NAME} 0) | ||
|
||
# create map/bin/hex/uf2 file etc. | ||
pico_add_extra_outputs(${NAME}) | ||
|
||
############################################################################## | ||
|
||
set(NAME "fade") | ||
|
||
add_executable(${NAME} | ||
common/main.c | ||
fade/run.c | ||
) | ||
target_include_directories(${NAME} PRIVATE | ||
${CMAKE_CURRENT_LIST_DIR}/../include | ||
) | ||
target_link_libraries(${NAME} | ||
picofuse | ||
) | ||
|
||
# enable usb output, disable uart output | ||
pico_enable_stdio_usb(${NAME} 1) | ||
pico_enable_stdio_uart(${NAME} 0) | ||
|
||
# create map/bin/hex/uf2 file etc. | ||
pico_add_extra_outputs(${NAME}) | ||
|
||
############################################################################## | ||
|
||
set(NAME "gpio_in") | ||
|
||
add_executable(${NAME} | ||
common/main.c | ||
gpio_in/run.c | ||
) | ||
target_include_directories(${NAME} PRIVATE | ||
${CMAKE_CURRENT_LIST_DIR}/../include | ||
) | ||
target_link_libraries(${NAME} picofuse) | ||
|
||
# enable usb output, disable uart output | ||
pico_enable_stdio_usb(${NAME} 1) | ||
pico_enable_stdio_uart(${NAME} 0) | ||
|
||
# create map/bin/hex/uf2 file etc. | ||
pico_add_extra_outputs(${NAME}) | ||
|
||
############################################################################## | ||
|
||
set(NAME "inky") | ||
|
||
add_executable(${NAME} | ||
common/main.c | ||
inky/run.c | ||
) | ||
target_include_directories(${NAME} PRIVATE | ||
${CMAKE_CURRENT_LIST_DIR}/../include | ||
) | ||
target_link_libraries(${NAME} | ||
picofuse | ||
uc8151 | ||
) | ||
|
||
# enable usb output, disable uart output | ||
pico_enable_stdio_usb(${NAME} 1) | ||
pico_enable_stdio_uart(${NAME} 0) | ||
|
||
# create map/bin/hex/uf2 file etc. | ||
pico_add_extra_outputs(${NAME}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <picofuse/picofuse.h> | ||
|
||
#define LED_DELAY_MS 250 | ||
|
||
/* @brief LED Callback | ||
*/ | ||
void led_callback(fuse_t *self, fuse_event_t *evt, void *user_data) | ||
{ | ||
assert(self); | ||
assert(evt); | ||
|
||
// LED is the user_data field | ||
fuse_led_t *led = (fuse_led_t *)user_data; | ||
|
||
// Blink the LED | ||
fuse_led_set(led, !fuse_led_get(led)); | ||
} | ||
|
||
int run(fuse_t *self) | ||
{ | ||
// LED output | ||
fuse_led_t *led = (fuse_led_t *)fuse_retain(self, fuse_new_led(self)); | ||
assert(led); | ||
|
||
// Register timer callback on core 0 | ||
assert(fuse_register_callback(self, FUSE_EVENT_TIMER, 0, led_callback)); | ||
|
||
// Schedule timer to run every second | ||
assert(fuse_timer_schedule(self, LED_DELAY_MS, true, led)); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include <picofuse/picofuse.h> | ||
|
||
#define GPIO_SPI_SCK 2 // SCK = GPIO2, Physical pin 4 | ||
#define GPIO_SPI_TX 3 // TX = GPIO3, Physical pin 5 | ||
#define GPIO_SPI_RX 4 // RX = GPIO4, Physical pin 6 | ||
#define GPIO_SPI_CS 5 // CS = GPIO5, Physical pin 7 | ||
|
||
/* @brief Callback when there is a measurement from the BME280 | ||
*/ | ||
void bme280_callback(fuse_t *self, fuse_event_t *evt, void* user_data) | ||
{ | ||
assert(self); | ||
assert(evt); | ||
assert(user_data); | ||
|
||
// Print the measurement | ||
fuse_bme280_measurement_t* meas = (fuse_bme280_measurement_t*)user_data; | ||
fuse_printf(self, "Temp: %f\n",meas->temperature); | ||
if (meas->pressure) { | ||
fuse_printf(self, "Pressure: %f\n",meas->pressure); | ||
} | ||
if (meas->humidity) { | ||
fuse_printf(self, "Humidity: %f\n",meas->humidity); | ||
} | ||
} | ||
|
||
/* @brief Callback for printing out memory stats | ||
*/ | ||
void stats_callback(fuse_t *self, fuse_event_t *evt, void* user_data) | ||
{ | ||
assert(self); | ||
assert(evt); | ||
|
||
// user_data should be NULL | ||
if (user_data) { | ||
return; | ||
} | ||
|
||
// Print the stats | ||
size_t cur, max; | ||
fuse_memstats(self, &cur, &max); | ||
|
||
// Print the stats | ||
fuse_printf(self, "Memory: %u bytes/%u bytes\n", cur, max); | ||
} | ||
|
||
int run(fuse_t *self) | ||
{ | ||
// Create an SPI interface | ||
fuse_spi_data_t config = { | ||
.cs = GPIO_SPI_CS, | ||
.ck = GPIO_SPI_SCK, | ||
.tx = GPIO_SPI_TX, | ||
.rx = GPIO_SPI_RX, | ||
.baudrate = 500 * 1000, // This example will use SPI0 at 0.5MHz | ||
.xfr_delayms = 10, | ||
}; | ||
|
||
// Create a new BME280 | ||
fuse_bme280_t* bme280 = (fuse_bme280_t* )fuse_retain(self, fuse_new_bme280(self, fuse_new_spi(self, config))); | ||
assert(bme280); | ||
|
||
// Print driver details | ||
fuse_printf(self, "bme280 initialized: %v\n", bme280); | ||
|
||
// Register a callback on core 0 for the measured data | ||
assert(fuse_register_callback(self, FUSE_EVENT_BME280, 0, bme280_callback)); | ||
|
||
// Register a callback on core 0 for timer | ||
assert(fuse_register_callback(self, FUSE_EVENT_TIMER, 0, stats_callback)); | ||
|
||
// Read measurements every 10 secs | ||
fuse_bme280_read(self, bme280, 10 * 1000); | ||
|
||
// Timer to output the memory stats every minute | ||
fuse_timer_t* timer = fuse_timer_schedule(self, 27 * 1000, true, NULL); | ||
assert(timer); | ||
|
||
return 0; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include <picofuse/picofuse.h> | ||
#include <pico/stdlib.h> | ||
|
||
/* @brief Callback when there is a wrap-around on the PWM counter | ||
*/ | ||
void pwm_callback(fuse_t *self, fuse_event_t *evt, void *user_data) | ||
{ | ||
assert(self); | ||
assert(evt); | ||
|
||
static int fade = 0; | ||
static bool going_up = true; | ||
|
||
if (going_up) | ||
{ | ||
++fade; | ||
if (fade > 0xFF) | ||
{ | ||
fade = 0xFF; | ||
going_up = false; | ||
} | ||
} | ||
else | ||
{ | ||
--fade; | ||
if (fade < 1) | ||
{ | ||
fade = 1; | ||
going_up = true; | ||
} | ||
} | ||
|
||
fuse_pwm_set_duty_cycle_b(self, (fuse_pwm_t *)user_data, fade); | ||
} | ||
|
||
int run(fuse_t *self) | ||
{ | ||
fuse_pwm_config_t pwm_config = { | ||
.gpio_b = PICO_DEFAULT_LED_PIN, | ||
.duty_cycle_b = 0xFF, | ||
.freq = 512 * 1000, | ||
.event = true, | ||
}; | ||
fuse_watchdog_config_t watchdog_config = {}; | ||
|
||
// Watchdog | ||
fuse_watchdog_t *watchdog = (fuse_watchdog_t *)fuse_retain(self, fuse_new_watchdog(self, watchdog_config)); | ||
assert(watchdog); | ||
fuse_debugf(self, "WATCHDOG: %v\n", watchdog); | ||
|
||
// PWM | ||
fuse_pwm_t *pwm = (fuse_pwm_t *)fuse_retain(self, fuse_new_pwm(self, pwm_config)); | ||
assert(pwm); | ||
fuse_register_callback(self, FUSE_EVENT_PWM, 0, pwm_callback); | ||
fuse_debugf(self, "PWM: %v\n", pwm); | ||
|
||
return 0; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.