forked from Ralim/IronOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
190 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# WS2812B RGB Modding (Pinecil V2) | ||
|
||
## What is it? | ||
|
||
The idea of this mod is to bring the RGB feature of the MHP30 to the Pinecil V2. | ||
Use a transparent shell for a better effect. | ||
|
||
Pinecil V2 has a free GPIO_12 accessible through TP10, which is along the screen, cf [Pinecil PCB placement v2.0](https://files.pine64.org/doc/Pinecil/Pinecil_PCB_placement_v2.0_20220608.pdf) page 3. (TP9 (GPIO_14) is also available but hidden below the screen. If you want to use it, change `WS2812B_Pin` in `source/Core/BSP/Pinecilv2/Pins.h`.) | ||
|
||
We'll using it to drive a WS2812B and let the color logic already present for the MHP30 do its magic: | ||
|
||
- green when temperature is safe (< 55°C) | ||
- pulsing red when heating | ||
- solid red when desired temperature is reached | ||
- orange when cooling down | ||
|
||
## Electrical considerations | ||
|
||
WS2812B requires a Vdd between 3.5 and 5.3V and Vih (high level of input signal) must be at least 0.7*Vdd. | ||
Pinecil V2 GPIO levels are 3.3V and the 5V rail is actually max 4.6V. | ||
So we can directly power the WS2812B on the 5V rail and command it with the GPIO without need for a level shifter, or for a Zener diode to clamp Vdd. | ||
|
||
## How to wire it? | ||
|
||
- WS2812B pin 1 (Vdd) is connected to the "5V" rail, e.g. on the C8 capacitor as illustrated [here](https://github.com/Ralim/IronOS/issues/1410#issuecomment-1296064392). | ||
- WS2812B pin 3 (Vss) is connected to the Pinecil GND, e.g. on the U10 pad at the back of the PCB, below R35, as illustrated [here](https://github.com/Ralim/IronOS/issues/1410#issuecomment-1296064392). | ||
- WS2812B pin 4 (Din) is connected to TP10. | ||
|
||
You can use e.g. 0.1-mm enameled wire and isolate connections with UV glue to avoid any shortcut. | ||
|
||
## How to enable it in the code? | ||
|
||
`make firmware-EN model=Pinecilv2 ws2812b_enable=1` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* WS2812B.h | ||
* | ||
* Created on: 9 July 2023 | ||
* Author: Doegox | ||
* Currently for RISC-V architecture only | ||
* Based on WS2812.h by Ralim for STM32 | ||
*/ | ||
#include "Pins.h" | ||
#include "Setup.h" | ||
#include <stddef.h> | ||
#include <stdint.h> | ||
#include <string.h> | ||
|
||
#ifndef CORE_DRIVERS_WS2812B_H_ | ||
#define CORE_DRIVERS_WS2812B_H_ | ||
|
||
#ifndef WS2812B_LED_CHANNEL_COUNT | ||
#define WS2812B_LED_CHANNEL_COUNT 3 | ||
#endif | ||
|
||
#define WS2812B_RAW_BYTES_PER_LED (WS2812B_LED_CHANNEL_COUNT * 8) | ||
|
||
template <uint16_t LED_PIN, int LED_COUNT> class WS2812B { | ||
private: | ||
uint8_t leds_colors[WS2812B_LED_CHANNEL_COUNT * LED_COUNT]; | ||
|
||
public: | ||
void led_update() { | ||
__disable_irq(); | ||
// Bitbang it out as our cpu irq latency is too high | ||
for (unsigned int i = 0; i < sizeof(leds_colors); i++) { | ||
// Shove out MSB first | ||
for (int x = 0; x < 8; x++) { | ||
if ((leds_colors[i] & (1 << (7 - x))) == (1 << (7 - x))) { | ||
gpio_write(LED_PIN, 1); | ||
for (int k = 0; k < 27; k++) { | ||
__ASM volatile("nop"); | ||
} | ||
gpio_write(LED_PIN, 0); | ||
for (int k = 0; k < 10; k++) { | ||
__ASM volatile("nop"); | ||
} | ||
} else { | ||
gpio_write(LED_PIN, 1); | ||
for (int k = 0; k < 10; k++) { | ||
__ASM volatile("nop"); | ||
} | ||
gpio_write(LED_PIN, 0); | ||
for (int k = 0; k < 27; k++) { | ||
__ASM volatile("nop"); | ||
} | ||
} | ||
} | ||
} | ||
__enable_irq(); | ||
} | ||
|
||
void init(void) { memset(leds_colors, 0, sizeof(leds_colors)); | ||
gpio_set_mode(LED_PIN, GPIO_OUTPUT_MODE); | ||
gpio_write(LED_PIN, 1); | ||
led_set_color(0, 0, 0xFF, 0); // green | ||
led_update(); | ||
} | ||
|
||
void led_set_color(size_t index, uint8_t r, uint8_t g, uint8_t b) { | ||
leds_colors[index * WS2812B_LED_CHANNEL_COUNT + 0] = g; | ||
leds_colors[index * WS2812B_LED_CHANNEL_COUNT + 1] = r; | ||
leds_colors[index * WS2812B_LED_CHANNEL_COUNT + 2] = b; | ||
} | ||
|
||
void led_set_color_all(uint8_t r, uint8_t g, uint8_t b) { | ||
for (int index = 0; index < LED_COUNT; index++) { | ||
leds_colors[index * WS2812B_LED_CHANNEL_COUNT + 0] = g; | ||
leds_colors[index * WS2812B_LED_CHANNEL_COUNT + 1] = r; | ||
leds_colors[index * WS2812B_LED_CHANNEL_COUNT + 2] = b; | ||
} | ||
} | ||
}; | ||
|
||
#endif /* CORE_DRIVERS_WS2812B_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters