Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,4 @@ zephyr_library_sources_ifdef(CONFIG_USE_SEVEN_SEGMENT_DISPLAY src/sevensegment.c
zephyr_library_sources_ifdef(CONFIG_USE_READY_LED src/ready_led.c)
zephyr_library_sources_ifdef(CONFIG_USE_METEOROLOGY_SENSORS src/meteorology.c)
zephyr_library_sources_ifdef(CONFIG_USE_LOWPOWER src/low_power.c)
zephyr_library_sources_ifdef(CONFIG_MFRC522 src/mfrc522.c)
zephyr_library_sources_ifdef(CONFIG_ST25DVXXK src/st25dvxxk.c)
zephyr_library_sources_ifdef(CONFIG_PN532 src/pn532.c)
zephyr_library_sources_ifdef(CONFIG_USE_MFRC522 src/mfrc522.c)
zephyr_library_sources_ifdef(CONFIG_ST25DVXXK src/st25dvxxk.c)

61 changes: 61 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Sensors

This directory contains drivers, helpers and example code for sensors and
actuators used in Zephyr-based projects.

## Quick usage

Add the sensors library to your application's CMakeLists.txt:

```cmake
add_subdirectory(sensors)
target_link_libraries(app PRIVATE sensors)
```

Enable component configuration in your project's `prj.conf` (examples):

```
# Enable GPIO LED helpers
CONFIG_USE_GPIO_LED=y
# Enable motion sensor helper
CONFIG_USE_MOTION_SENSOR=y
```

## Patches

The `patches/` directory contains patch files required for specific boards
or Zephyr modules. Patch paths use the format `module/NN_description.patch`.
Apply with `patch -p1 < path/to/patch` from a Zephyr source tree when needed.

## Documentation

API and developer documentation is in the `doc/` directory and can be
generated with Doxygen (run `doxygen` from the `doc/` folder).

## Public headers and short notes

The `sensors/include` directory exposes small helper APIs used by apps:

- `gpio_led.h` — GPIO-driven LED helpers (`gpio_led_init()`,
`gpio_led_set_led()`); enabled with `CONFIG_USE_GPIO_LED`.
- `ready_led.h` — higher-level ready/status LED helpers used on some
boards.
- `button.h` — button state and callback registration (`button_init()`).
- `motion_sensor.h` — motion sensor init and callback (`motion_sensor_init()`);
enabled with `CONFIG_USE_MOTION_SENSOR`.
- `stripled.h`, `pwmled.h`, `sevensegment.h` — LED strip, PWM LED and
7-segment helpers.
- `rfid.h`, `pn532.h`, `mfrc522.h`, `st25dvxxk.h` — RFID / NFC related drivers.

## Examples and boards

Board overlays and configuration live under `boards/` and `zephyr/`.
See the board-specific `.overlay` files for GPIO assignments and device-tree
settings used by drivers in this directory.

## Next steps

- Add per-header API notes to the headers in `sensors/include` (short
descriptions are present in header comments).
- If you want, I can run a repo-wide search to list all callers of the
public APIs and update examples.
55 changes: 0 additions & 55 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -200,61 +200,6 @@ config USE_METEOROLOGY_SENSORS
help
Use meteorology sensors (BMP280, BME280 etc)

config MFRC522
bool "Use mfrc522 rfid chip"
select SPI
default n
help
Use the mfrc522 rfid chip

config MFRC522_INIT_PRIORITY
int "Init priority"
depends on MFRC522
default 90
help
Device driver initialization priority.



# ST25DVXXK NFC/RFID tag configuration options

config ST25DVXXK
bool "ST25DVXXK NFC/RFID tag driver"
default n
config USE_MFRC522
bool "Use mfrc522 rfid chip"
default n
help
Use the mfrc522 rfid chip
# ST25DVXXK NFC/RFID tag configuration options

config ST25DVXXK
bool "ST25DVXXK NFC/RFID tag driver"
default y
select I2C
help
Enable driver for ST25DVXXK NFC/RFID tag.

config ST25DVXXK_INIT_PRIORITY
int "Init priority"
depends on ST25DVXXK
default 90
help
Device driver initialization priority.

config PN532
bool "PN532 NFC driver"
default n
help
Enable device driver for PN532 NFC/RFID device

config PN532_INIT_PRIORITY
int "Init priority for the PN532"
depends on PN532
default 90
help
Device driver initialization priority

module = SENSORS
module-str = "Sensors"
module-help = Enables logging for the sensors module
Expand Down
37 changes: 33 additions & 4 deletions doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -944,8 +944,20 @@ WARN_LOGFILE =
# Note: If this tag is empty the current directory is searched.

INPUT = \
../src/ready_led.c ../src/sensor_log.c ../src/button.c \
../include/ready_led.h ../include/button.h
../src/adc.c ../include/adc.h \
../src/button.c ../include/button.h \
../sr/gpio_led.c ../include/gpio_led.h\
../src/ky40.c ../incude/ky40.h \
../src/low_power.c ../include/low_power.h \
../src/meteorology.c ../include/meteorology.h \
../src/motion_sensor.c ../include/motion_sensor.h \
../src/pn532.c ../include/on532.h \
../src/pwmled.c ../include/pwmled.h \
../src/ready_led.c ../include/ready_led.h \
../src/sensor_log.c ../include/sensor_logging.h \
../src/sevensegment.c ../include/sevensegment.h \
../src/st25dvxxk.c ../include/st25dvxxk.h \
../src/stripled.c ../include/stripled.h

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Expand Down Expand Up @@ -2433,8 +2445,25 @@ INCLUDE_FILE_PATTERNS =
# recursively expanded use the := operator instead of the = operator.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

PREDEFINED = CONFIG_USE_READY_LED \
CONFIG_USE_BUTTON
PREDEFINED = \
CONFIG_USE_ADC \
CONFIG_USE_ADC_DEBOUNCE \
CONFIG_USE_BUTTON \
CONFIG_USE_READY_LED \
CONFIG_USE_READY_LED_CONTROLLER \
CONFIG_USE_READY_LED_GPIO \
CONFIG_USE_READY_LED_PICO_W \
CONFIG_USE_READY_LED_PWM \
CONFIG_USE_READY_LED_STRIP \
CONFIG_USE_GPIO_LED \
CONFIG_USE_KY40 \
CONFIG_USE_LOWPOWER \
CONFIG_USE_METEOROLOGY_SENSORS \
CONFIG_USE_MOTION_SENSOR \
CONFIG_USE_PWM_LED \
CONFIG_MOTION_SENSOR_DEBOUNCE \
CONFIG_USE_FOUR_ELEMENT_SEVEN_SEGMENT_DISPLAY \
CONFIG_USE_STRIP_LED \

# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The
Expand Down
41 changes: 41 additions & 0 deletions include/adc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2023 Beechwoods Software, Inc brad@beechwoods.com
* All Rights Reserved
* SPDX-License-Identifier: Apache 2.0
*/

#pragma once

/**
* @file adc.h
* @brief ADC sensor interface
*
* Provides a small API to initialize ADC channels configured through
* devicetree and to read sensor levels.
*/

/**
* @brief
* Initialize the adc
*/
int bws_adc_init();

/**
* @brief get the number of sensors
* @return The number of sensors
*/
int bws_adc_get_num_sensors();
/**
* @brief get the level of a sensor
* @param num The sensor number
* @return The value of the sensor
*/
int bws_adc_get_sensor(int num);

#ifdef CONFIG_USE_ADC_DEBOUNCE
/**
* @brief dump the debounce data for a sensor
* @param num The sensor number
*/
void bws_adc_dump_debounce(int num);
#endif
71 changes: 71 additions & 0 deletions include/gpio_led.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2023 Beechwoods Software Inc.
* All Rights Reserved.
* SPDX-License-Identifier: Apache 2.0
*/

#pragma once

#include <stdbool.h>

/**
* @file gpio_led.h
* @brief GPIO-based LED helper API
*
* Provides initialization and simple control primitives for LEDs
* driven by GPIO lines. This header is conditionally compiled when
* `CONFIG_USE_GPIO_LED` is enabled.
*/

/**
* @def GPIO_ZONE_SIZE
* @brief Number of entries in a color zone array.
*/
#define GPIO_ZONE_SIZE 6

/**
* @typedef gpio_color_zone_t
* @brief Array of integers representing different color zone thresholds.
*
* The array contains GPIO_ZONE_SIZE integers describing color thresholds
* or levels. The first element (index 0) is the highest legal value and
* the last element (index GPIO_ZONE_SIZE - 1) is the lowest legal value.
*/
typedef int gpio_color_zone_t[GPIO_ZONE_SIZE];

#ifdef CONFIG_USE_GPIO_LED

/**
* @brief Post-initialization hook for the GPIO LED subsystem.
*
* Should be called after system boot or when bringing the LED subsystem
* up from a suspended state. Typically used to restore LED state.
*/
void gpio_led_post(void);

/**
* @brief Initialize the GPIO-based LED subsystem.
*
* Performs any hardware configuration required to manage LEDs via GPIO.
*
* @return 0 on success, negative error code on failure.
*/
int gpio_led_init(void);

/**
* @brief Return number of LEDs managed by the GPIO LED driver.
*
* @return Number of LEDs (>=0) or a negative error code on failure.
*/
int gpio_led_get_num_leds(void);

/**
* @brief Set the state of a GPIO-controlled LED.
*
* @param led Index of the LED (0-based).
* @param value true to turn the LED on, false to turn it off.
* @return 0 on success, negative error code on failure.
*/
int gpio_led_set_led(int led, bool value);

#endif /* CONFIG_USE_GPIO_LED */
27 changes: 27 additions & 0 deletions include/ky40.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Beechwoods Software, Inc. 2023 brad@beechwoods.com
* All Rights Reserved
* SPDX-License-Identifier: Apache 2.0
*/



#pragma once

#include <zephyr/input/input.h>

/**
* @file ky40.h
* @brief KY-040 rotary encoder helper
*
* Thin wrapper around Zephyr input events for handling the KY-040
* rotary encoder and registering rotation/click callbacks.
*/

typedef const struct device * const ky40_device_t;

typedef void (*ky40_event_callback)(struct input_event *, int);

int ky40_init(ky40_event_callback func);
int ky40_get_rotation();
void ky40_set_callback(ky40_event_callback func, int index);
34 changes: 34 additions & 0 deletions include/low_power.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2023 Beechwoods Software Inc.
* All Rights Reserved.
* SPDX-License-Identifier: Apache 2.0
*/

#pragma once


/**
* @file low_power.h
* @brief Low power / sleep helper API
*
* Provides a thin API to put the system into light or deep sleep modes.
*/

typedef enum sleep_type {
LIGHT_SLEEP,
DEEP_SLEEP
}sleep_type_t;

/**
* @brief Initialize low-power facilities
* @return 0 on success, negative errno on failure
*/
int low_power_init();

/**
* @brief Set the system sleep mode
* @param sleep_type The sleep mode to enter
* @return 0 on success, negative errno on failure
*/
int low_power_set(sleep_type_t sleep_type);

Loading