Skip to content

Commit

Permalink
Merge pull request #16 from mutablelogic/dev
Browse files Browse the repository at this point in the history
Added updates for GPIO
  • Loading branch information
djthorpe authored Sep 3, 2024
2 parents f57b44f + dc3832a commit 2752594
Show file tree
Hide file tree
Showing 27 changed files with 189 additions and 219 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ Whenever you target a different board, use `make clean` before `make picotool` a

## References

* Pico SDK
* Repository https://github.com/raspberrypi/pico-sdk
* Documentation (in PDF) https://datasheets.raspberrypi.org/pico/raspberry-pi-pico-c-sdk.pdf


* Pico SDK
* Repository https://github.com/raspberrypi/pico-sdk
* Documentation (in PDF) https://datasheets.raspberrypi.org/pico/raspberry-pi-pico-c-sdk.pdf
28 changes: 24 additions & 4 deletions examples/picofuse/gpio_in/run.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
#include <picofuse/picofuse.h>

int run(fuse_t *fuse)
/* @brief Callback when there is a rising or falling edge on GPIO pin
*/
void gpio_callback(fuse_t *self, fuse_event_t *evt, void *user_data)
{
// GPIO Pin 26 input
fuse_gpio_t *pin = fuse_new_gpio(fuse, 26, FUSE_GPIO_IN);
assert(pin);
assert(self);
assert(evt);
assert(user_data);

// Print the event
fuse_printf(self, "Event: evt=%v user_data=%p\n", evt, user_data);
}

int run(fuse_t *self)
{
// Initialize picofuse
picofuse_init(self);

// GPIO inputs
assert(fuse_retain(self, fuse_new_gpio(self, 23, FUSE_GPIO_IN)));
assert(fuse_retain(self, fuse_new_gpio(self, 12, FUSE_GPIO_PULLUP)));
assert(fuse_retain(self, fuse_new_gpio(self, 13, FUSE_GPIO_PULLUP)));
assert(fuse_retain(self, fuse_new_gpio(self, 14, FUSE_GPIO_PULLUP)));

// Register a callback
assert(fuse_register_callback(self, FUSE_EVENT_GPIO, 0, gpio_callback));

return 0;
}
35 changes: 0 additions & 35 deletions include/fuse/device.h

This file was deleted.

2 changes: 2 additions & 0 deletions include/fuse/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#ifndef FUSE_EVENT_H
#define FUSE_EVENT_H

#include "value.h"

// Define the event types
#define FUSE_EVENT_NULL 0x00 ///< NULL event
#define FUSE_EVENT_TIMER 0x01 ///< Timer event
Expand Down
40 changes: 0 additions & 40 deletions include/fuse/flags.h

This file was deleted.

2 changes: 1 addition & 1 deletion include/fuse/fuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
typedef struct fuse_application fuse_t;

#include "assert.h"
#include "device.h"
#include "event.h"
#include "list.h"
#include "magic.h"
Expand All @@ -22,6 +21,7 @@ typedef struct fuse_application fuse_t;
#include "printf.h"
#include "random.h"
#include "sleep.h"
#include "str.h"
#include "timer.h"
#include "value.h"

Expand Down
1 change: 1 addition & 0 deletions include/fuse/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
#ifndef FUSE_RANDOM_H
#define FUSE_RANDOM_H

#include <stdint.h>

/** @brief Return a random unsigned 32 bit number
Expand Down
2 changes: 1 addition & 1 deletion include/fuse/string.h → include/fuse/str.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @file string.h
/** @file str.h
* @brief String storage and manipulation
*
* This file contains the function prototypes for working with UTF-8 strings
Expand Down
10 changes: 6 additions & 4 deletions include/fuse/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "fuse.h"
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>

/** @brief The representation of a fuse value
*/
Expand Down Expand Up @@ -68,19 +70,19 @@ fuse_value_t *fuse_new_value_ex(fuse_t *self, const uint16_t magic, const void *
* This method increments the reference count of the value, to take ownership of the value.
*
* @param self The fuse instance
* @param value The value to retain
* @param value The value to retain, which must be a fuse_value_t*
* @return The retained value, or NULL if the value could not be retained
*/
fuse_value_t *fuse_retain(fuse_t *self, fuse_value_t *value);
fuse_value_t *fuse_retain(fuse_t *self, void *value);

/** @brief Release a value and destroy it if the reference count reaches 0
*
* This method decrements the reference count of the value. When it reaches zero, it is
* freed.
*
* @param self The fuse instance
* @param ptr The value to release
* @param ptr The value to release, which must be a fuse_value_t*
*/
void fuse_release(fuse_t *self, fuse_value_t *value);
void fuse_release(fuse_t *self, void *value);

#endif /* FUSE_VALUE_H */
3 changes: 2 additions & 1 deletion include/picofuse/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ typedef enum
#define fuse_new_gpio(self, pin, func) \
((fuse_gpio_t *)fuse_new_gpio_ex((self), (pin), (func), __FILE__, __LINE__))
#else
#define fuse_new_gpio((self, pin, func)((fuse_gpio_t *)fuse_new_gpio_ex((self), (pin), (func), 0, 0))
#define fuse_new_gpio(self, pin, func) \
((fuse_gpio_t *)fuse_new_gpio_ex((self), (pin), (func), 0, 0))
#endif

/** @brief An opaque event object
Expand Down
6 changes: 6 additions & 0 deletions include/picofuse/picofuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@
#include <fuse/fuse.h>
#include "gpio.h"

/* @brief Register picofuse types
*
* @param fuse The fuse application
*/
void picofuse_init(fuse_t *fuse);

#endif
3 changes: 1 addition & 2 deletions src/fuse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ add_library(${NAME} STATIC
alloc_builtin.c
base64.c
data.c
device.c
event.c
ftostr.c
fuse.c
Expand All @@ -20,7 +19,7 @@ add_library(${NAME} STATIC
random_pico.c
random_posix.c
sleep_posix.c
string.c
str.c
strtostr.c
timer_darwin.c
timer_linux.c
Expand Down
1 change: 1 addition & 0 deletions src/fuse/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>

/** @brief Represents a memory block header
*/
Expand Down
23 changes: 0 additions & 23 deletions src/fuse/device.c

This file was deleted.

1 change: 1 addition & 0 deletions src/fuse/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define FUSE_PRIVATE_EVENT_H

#include <fuse/fuse.h>
#include <stdint.h>

/** @brief Event data
*/
Expand Down
6 changes: 3 additions & 3 deletions src/fuse/fuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "number.h"
#include "null.h"
#include "printf.h"
#include "string.h"
#include "str.h"
#include "timer.h"

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -293,7 +293,7 @@ static void fuse_runloop(fuse_t *self, uint8_t q)
assert(q < 2);

// Run the loop
fuse_debugf(self, "fuse_runloop: core %u (exit_code=%d)\n", q, self->exit_code);
fuse_debugf(self, "fuse_runloop: core %u: start\n", q);
while (!self->exit_code)
{
// Pop event from the event queue
Expand All @@ -313,7 +313,7 @@ static void fuse_runloop(fuse_t *self, uint8_t q)
drained = fuse_drain(self, 10);
if (drained > 0)
{
fuse_debugf(self, "fuse_runloop: drained %lu item(s)\n", drained);
fuse_debugf(self, "fuse_runloop: drained %u item(s)\n", drained);
}
else
{
Expand Down
5 changes: 5 additions & 0 deletions src/fuse/fuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
*/
#ifndef FUSE_PRIVATE_FUSE_H
#define FUSE_PRIVATE_FUSE_H

#include <stdbool.h>
#include <fuse/fuse.h>
#include <fuse/magic.h>
#include <fuse/event.h>
#include "alloc.h"
#include "event.h"
#include "fuse.h"
#include "list.h"

///////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions src/fuse/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#ifndef FUSE_PRIVATE_LIST_H
#define FUSE_PRIVATE_LIST_H

#include <stddef.h>

/** @brief Represents a linked list
*/
struct fuse_list
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions src/fuse/string.h → src/fuse/str.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#ifndef FUSE_PRIVATE_STRING_H
#define FUSE_PRIVATE_STRING_H

#include "fuse.h"

/** @brief Register type for string values
*/
void fuse_register_value_string(fuse_t *self);
Expand Down
15 changes: 8 additions & 7 deletions src/fuse/value.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,33 @@ fuse_value_t *fuse_new_value_ex(fuse_t *self, const uint16_t magic, const void *

/** @brief Retain the value and return it.
*/
fuse_value_t *fuse_retain(fuse_t *self, fuse_value_t *value)
fuse_value_t *fuse_retain(fuse_t *self, void *value)
{
assert(self);
assert(value == NULL || fuse_allocator_magic(self->allocator, value) < FUSE_MAGIC_COUNT);
assert(value == NULL || fuse_allocator_magic(self->allocator, (fuse_value_t *)value) < FUSE_MAGIC_COUNT);

// Retain value
if (value != NULL)
{
fuse_allocator_retain(self->allocator, value);
fuse_allocator_retain(self->allocator, (fuse_value_t *)value);
}

// Return value
return value;
return (fuse_value_t *)value;
}

/** @brief Release a value and destroy it if the reference count reaches 0
*/
void fuse_release(fuse_t *self, fuse_value_t *value)
void fuse_release(fuse_t *self, void *value)
{
assert(self);
assert(value == NULL || fuse_allocator_magic(self->allocator, value) < FUSE_MAGIC_COUNT);
assert(value == NULL || fuse_allocator_magic(self->allocator, (fuse_value_t *)value) < FUSE_MAGIC_COUNT);

// Decrement the reference count
if (value != NULL)
{
if(fuse_allocator_release(self->allocator, value)) {
if (fuse_allocator_release(self->allocator, (fuse_value_t *)value))
{
// Indicate we should drain the memory pool
self->drain = true;
}
Expand Down
1 change: 1 addition & 0 deletions src/fuse/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define FUSE_PRIVATE_VALUE_H

#include <fuse/fuse.h>
#include <stddef.h>

/** @brief Represents a value
*
Expand Down
2 changes: 2 additions & 0 deletions src/picofuse/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
set(NAME "picofuse")
add_library(${NAME} STATIC
gpio.c
picofuse.c
)

target_include_directories(${NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/../../include
${CMAKE_CURRENT_LIST_DIR}/../fuse
)

target_link_libraries(${NAME}
Expand Down
Loading

0 comments on commit 2752594

Please sign in to comment.