Skip to content

Commit

Permalink
Add neopixel driver
Browse files Browse the repository at this point in the history
  • Loading branch information
nateinaction committed Oct 23, 2024
1 parent 0bb800f commit ce5db31
Show file tree
Hide file tree
Showing 10 changed files with 238 additions and 0 deletions.
2 changes: 2 additions & 0 deletions BroncoDeployment/Top/instances.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ module BroncoDeployment {

instance rateDriver: Arduino.HardwareRateDriver base id 0x4A00

instance neoPixelDriver: Drv.NeoPixelDriver base id 0x4B00

# Hub Connections

instance hub: Svc.GenericHub base id 0x5000
Expand Down
2 changes: 2 additions & 0 deletions Components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/BroncoOreMessageHandler/")

add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Radio/")

add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Drv/")
5 changes: 5 additions & 0 deletions Components/Drv/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ports
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/NeoPixelDriverPorts/")

# Components
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/NeoPixelDriver/")
18 changes: 18 additions & 0 deletions Components/Drv/NeoPixelDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
####
# F prime CMakeLists.txt:
#
# SOURCE_FILES: combined list of source and autocoding files
# MOD_DEPS: (optional) module dependencies
# UT_SOURCE_FILES: list of source files for unit tests
#
####
set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/NeoPixelDriver.fpp"
"${CMAKE_CURRENT_LIST_DIR}/NeoPixelDriver.cpp"
)

set(MOD_DEPS
Adafruit_NeoPixel
)

register_fprime_module()
50 changes: 50 additions & 0 deletions Components/Drv/NeoPixelDriver/NeoPixelDriver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// ======================================================================
// \title NeoPixelDriver.cpp
// \author nate
// \brief cpp file for NeoPixelDriver component implementation class
// ======================================================================

#include "Components/Drv/NeoPixelDriver/NeoPixelDriver.hpp"
#include "FpConfig.hpp"

namespace Drv {

// ----------------------------------------------------------------------
// Component construction and destruction
// ----------------------------------------------------------------------

#define PIN 24
#define NUMPIXELS 1

NeoPixelDriver ::NeoPixelDriver(const char* const compName) : NeoPixelDriverComponentBase(compName),
on_off(Fw::On::OFF),
red(0),
green(0),
blue(0),
pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800)
{
pixels.begin();
}

NeoPixelDriver ::~NeoPixelDriver() {}

// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------

void NeoPixelDriver ::neoPixelWrite_handler(NATIVE_INT_TYPE portNum, const Fw::On& on_off, U8 red, U8 green, U8 blue) {
this->on_off = on_off;
this->red = red;
this->green = green;
this->blue = blue;

if (Fw::On::ON == this->on_off) {
pixels.setPixelColor(0, pixels.Color(red, green, blue));
} else {
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
}

pixels.show();
}

} // namespace Drv
25 changes: 25 additions & 0 deletions Components/Drv/NeoPixelDriver/NeoPixelDriver.fpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Drv {
@ FPrime driver implmementation for Adafruit NeoPixel.
passive component NeoPixelDriver {

@ Port to turn modify the NeoPixel state.
sync input port neoPixelWrite: Drv.NeoPixelWrite

@ Event to report current NeoPixel state.
event NeoPixelState(on_off: Fw.On, $red: U8, green: U8, blue: U8) \
severity activity low \
format "LED is {} with color ({}, {}, {})"

###############################################################################
# Standard AC Ports: Required for Channels, Events, Commands, and Parameters #
###############################################################################
@ Port for requesting the current time
time get port timeCaller

@ Port for sending textual representation of events
text event port logTextOut

@ Port for sending events to downlink
event port logOut
}
}
50 changes: 50 additions & 0 deletions Components/Drv/NeoPixelDriver/NeoPixelDriver.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// ======================================================================
// \title NeoPixelDriver.hpp
// \author nate
// \brief hpp file for NeoPixelDriver component implementation class
// ======================================================================

#ifndef Drv_NeoPixelDriver_HPP
#define Drv_NeoPixelDriver_HPP

#include "Components/Drv/NeoPixelDriver/NeoPixelDriverComponentAc.hpp"
#include "lib/Adafruit_NeoPixel/Adafruit_NeoPixel.h"

namespace Drv {

class NeoPixelDriver : public NeoPixelDriverComponentBase {
public:
// ----------------------------------------------------------------------
// Component construction and destruction
// ----------------------------------------------------------------------

//! Construct NeoPixelDriver object
NeoPixelDriver(const char* const compName //!< The component name
);

//! Destroy NeoPixelDriver object
~NeoPixelDriver();

PRIVATE:
// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------

//! Handler implementation for onOff
void neoPixelWrite_handler(NATIVE_INT_TYPE portNum, //!< The port number
const Fw::On& on_off,
U8 red,
U8 green,
U8 blue) override;

PRIVATE:
Fw::On on_off;
U8 red;
U8 green;
U8 blue;
Adafruit_NeoPixel pixels;
};

} // namespace Drv

#endif
66 changes: 66 additions & 0 deletions Components/Drv/NeoPixelDriver/docs/sdd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Drv::NeoPixelDriver

FPrime driver implmementation for Adafruit NeoPixel.

## Usage Examples
Add usage examples here

### Diagrams
Add diagrams here

### Typical Usage
And the typical usage of the component here

## Class Diagram
Add a class diagram here

## Port Descriptions
| Name | Description |
|---|---|
|---|---|

## Component States
Add component states in the chart below
| Name | Description |
|---|---|
|---|---|

## Sequence Diagrams
Add sequence diagrams here

## Parameters
| Name | Description |
|---|---|
|---|---|

## Commands
| Name | Description |
|---|---|
|---|---|

## Events
| Name | Description |
|---|---|
|---|---|

## Telemetry
| Name | Description |
|---|---|
|---|---|

## Unit Tests
Add unit test descriptions in the chart below
| Name | Description | Output | Coverage |
|---|---|---|---|
|---|---|---|---|

## Requirements
Add requirements in the chart below
| Name | Description | Validation |
|---|---|---|
|---|---|---|

## Change Log
| Date | Description |
|---|---|
|---| Initial Draft |
12 changes: 12 additions & 0 deletions Components/Drv/NeoPixelDriverPorts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
####
# F prime CMakeLists.txt:
#
# SOURCE_FILES: combined list of source and autocoding files
# MOD_DEPS: (optional) module dependencies
#
####
set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/NeoPixelDriverPorts.fpp"
)

register_fprime_module()
8 changes: 8 additions & 0 deletions Components/Drv/NeoPixelDriverPorts/NeoPixelDriverPorts.fpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Drv {
port NeoPixelWrite(
on_off: Fw.On
$red: U8
green: U8
blue: U8
)
}

0 comments on commit ce5db31

Please sign in to comment.