Skip to content

Commit

Permalink
Add neopixel driver
Browse files Browse the repository at this point in the history
  • Loading branch information
nateinaction committed Nov 5, 2024
1 parent 0bb800f commit 1c2bed1
Show file tree
Hide file tree
Showing 11 changed files with 241 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "fprime-arduino"]
path = fprime-arduino
url = https://github.com/fprime-community/fprime-arduino.git
[submodule "lib/Adafruit_NeoPixel"]
path = lib/Adafruit_NeoPixel
url = https://github.com/adafruit/Adafruit_NeoPixel.git
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/")
1 change: 1 addition & 0 deletions Components/Drv/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
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()
41 changes: 41 additions & 0 deletions Components/Drv/NeoPixelDriver/NeoPixelDriver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// ======================================================================
// \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),
pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800)
{
pixels.begin();
}

NeoPixelDriver ::~NeoPixelDriver() {}

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

Drv::NeoPixelColor NeoPixelDriver ::neoPixelRead_handler(NATIVE_INT_TYPE portNum) {
uint16_t color = pixels.getPixelColor(0);
return Drv::NeoPixelColor((color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF);
}

void NeoPixelDriver ::neoPixelSet_handler(NATIVE_INT_TYPE portNum, const Drv::NeoPixelColor& color) {
pixels.setPixelColor(0, pixels.Color(color.getred(), color.getgreen(), color.getblue()));
pixels.show();
}

} // namespace Drv
43 changes: 43 additions & 0 deletions Components/Drv/NeoPixelDriver/NeoPixelDriver.fpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Type definition
module Drv {
struct NeoPixelColor {
$red: U8 @< Red color value.
green: U8 @< Green color value.
blue: U8 @< Blue color value.
}
}

# Port definition
module Drv {
port NeoPixelSet(color: NeoPixelColor)
port NeoPixelRead -> NeoPixelColor
}

# Component definition
module Drv {
@ FPrime driver implmementation for Adafruit NeoPixel.
passive component NeoPixelDriver {
@ Port to turn modify the NeoPixel state.
sync input port neoPixelSet: NeoPixelSet

@ Port to read the current NeoPixel state.
sync input port neoPixelRead: NeoPixelRead

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

###############################################################################
# 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
}
}
51 changes: 51 additions & 0 deletions Components/Drv/NeoPixelDriver/NeoPixelDriver.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// ======================================================================
// \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 neoPixelRead
//!
//! Port to read the current NeoPixel state.
Drv::NeoPixelColor neoPixelRead_handler(NATIVE_INT_TYPE portNum //!< The port number
) override;

//! Handler implementation for neoPixelSet
//!
//! Port to turn modify the NeoPixel state.
void neoPixelSet_handler(NATIVE_INT_TYPE portNum, //!< The port number
const Drv::NeoPixelColor& color) override;

PRIVATE:
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 |
1 change: 1 addition & 0 deletions lib/Adafruit_NeoPixel
Submodule Adafruit_NeoPixel added at aa798f
14 changes: 14 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
####
# F prime CMakeLists.txt:
#
# SOURCE_FILES: combined list of source and autocoding files
# MOD_DEPS: (optional) module dependencies
#
# Note: using PROJECT_NAME as EXECUTABLE_NAME
####
set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp"
)

add_library(Adafruit_NeoPixel ${SOURCE_FILES})
target_include_directories(Adafruit_NeoPixel PUBLIC "${CMAKE_CURRENT_LIST_DIR}/Adafruit_NeoPixel")
1 change: 1 addition & 0 deletions project.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Components")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/BroncoDeployment/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/lib")

0 comments on commit 1c2bed1

Please sign in to comment.