Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] WS2812 driver #85

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ $(TARGET)_INCLUDE += \
-I$(CMSIS_PATH)/source \
-I$(ATMEL_PATH)/include \


$(TARGET)_SRC += \
common/startup_samd21.c \
common/clock.c \
Expand Down
5 changes: 5 additions & 0 deletions firmware.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ TARGET := firmware
include common.mk
include usb.mk

$(TARGET)_INCLUDE += \
-I$(DRIVERS_PATH) \
-I$(DRIVERS_PATH)/system/interrupt/ \

$(TARGET)_SRC += \
firmware/main.c \
firmware/usb.c \
Expand All @@ -11,6 +15,7 @@ $(TARGET)_SRC += \
firmware/port.c \
firmware/usbpipe.c \
firmware/usbserial.c \
firmware/ws2812.c \

$(TARGET)_LDSCRIPT = common/samd21g15a_firmware_partition.ld
$(TARGET)_DEFINE += -D __SAMD21G15A__
5 changes: 5 additions & 0 deletions firmware/firmware.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,8 @@ void usbserial_in_completion();
void usbserial_dma_rx_completion();
void usbserial_dma_tx_completion();
void usbserial_handle_tc();

// ws2812.c
void ws2812_init(Pin p);
void ws2812_set_dma_addr(Pin p, void *addr);
void ws2812_begin_animation(Pin p);
3 changes: 3 additions & 0 deletions firmware/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ int main(void) {
port_init(&port_b, 2, &PORT_B, GCLK_PORT_B,
TCC_PORT_B, DMA_PORT_B_TX, DMA_PORT_B_RX);

// TEMPORARY
ws2812_init(PORT_B.power);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm misunderstanding, but this means that this driver is now "on by default"? I don't think this is a good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rwaldron I was just using this to check that my makefile changes worked and I could call the functions I wrote :) It won't be on by default in production.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it!


__enable_irq();
SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;
while (1) { __WFI(); }
Expand Down
69 changes: 69 additions & 0 deletions firmware/ws2812.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "firmware.h"
#include "tcc/tcc.h"

void _ws2812_set_pin_mux(Pin p);
void _ws2812_enable_clock();
void _ws2812_enable_tcc();

/*
Initializes the Counter Control of a specific pin
so that it's ready to output a waveform compatible
with the ws2812 protocol
*/
void ws2812_init(Pin p) {

_ws2812_set_pin_mux(p);

_ws2812_enable_clock();

_ws2812_enable_tcc();
}

/*
Sets the pin function to use the CCT
Section 30.5.1
*/
void _ws2812_set_pin_mux(Pin p) {
int8_t tcc_func = 0x05;

if (p.pin & 1) {
PORT->Group[p.group].PMUX[p.pin/2].bit.PMUXO = tcc_func;
} else {
PORT->Group[p.group].PMUX[p.pin/2].bit.PMUXE = tcc_func;
}

PORT->Group[p.group].PINCFG[p.pin].bit.PMUXEN = 1;

}

/*
Starts up the peripheral clock for the specific TCC used by the pin
Section 30.5.3
*/
void _ws2812_enable_clock() {
// system_apb_clock_set_mask(SYSTEM_CLOCK_APB_APBC, TCC0_GCLK_ID)
// TODO enable appropriate clock based on pin
// (GCLK_TCC0 vs GCLK_TCC1, etc.)
PM->APBCMASK.reg |= PM_APBCMASK_TCC0;
// GCLK->CLKCTRL.reg = GCLK_CLKCTRL_CLKEN |
// GCLK_CLKCTRL_GEN(GCLK_SYSTEM) |
// GCLK_CLKCTRL_ID(TCC0_GCLK_ID);
}

void _ws2812_enable_tcc() {

}

/*
Sets the DMA address the pin should read from
*/
void ws2812_set_dma_addr(Pin p, void *addr) {

}

/*
Begins an animation on a particular pin
*/
void ws2812_begin_animation(Pin p) {

}