Add init function to RGBLight driver struct (#23076)
This commit is contained in:
		
							parent
							
								
									23b7a02ebe
								
							
						
					
					
						commit
						f7cf40fa77
					
				
					 42 changed files with 306 additions and 93 deletions
				
			
		| 
						 | 
				
			
			@ -177,7 +177,7 @@ static void ws2812_dma_callback(void* p, uint32_t ct) {
 | 
			
		|||
    osalSysUnlockFromISR();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ws2812_init(void) {
 | 
			
		||||
void ws2812_init(void) {
 | 
			
		||||
    uint pio_idx = pio_get_index(pio);
 | 
			
		||||
    /* Get PIOx peripheral out of reset state. */
 | 
			
		||||
    hal_lld_peripheral_unreset(pio_idx == 0 ? RESETS_ALLREG_PIO0 : RESETS_ALLREG_PIO1);
 | 
			
		||||
| 
						 | 
				
			
			@ -196,7 +196,7 @@ bool ws2812_init(void) {
 | 
			
		|||
    STATE_MACHINE = pio_claim_unused_sm(pio, true);
 | 
			
		||||
    if (STATE_MACHINE < 0) {
 | 
			
		||||
        dprintln("ERROR: Failed to acquire state machine for WS2812 output!");
 | 
			
		||||
        return false;
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    uint offset = pio_add_program(pio, &ws2812_program);
 | 
			
		||||
| 
						 | 
				
			
			@ -246,8 +246,6 @@ bool ws2812_init(void) {
 | 
			
		|||
                         DMA_CTRL_TRIG_TREQ_SEL(pio == pio0 ? STATE_MACHINE : STATE_MACHINE + 8) |
 | 
			
		||||
                         DMA_CTRL_TRIG_PRIORITY(RP_DMA_PRIORITY_WS2812);
 | 
			
		||||
    // clang-format on
 | 
			
		||||
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void sync_ws2812_transfer(void) {
 | 
			
		||||
| 
						 | 
				
			
			@ -269,11 +267,6 @@ static inline void sync_ws2812_transfer(void) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
void ws2812_setleds(rgb_led_t* ledarray, uint16_t leds) {
 | 
			
		||||
    static bool is_initialized = false;
 | 
			
		||||
    if (unlikely(!is_initialized)) {
 | 
			
		||||
        is_initialized = ws2812_init();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    sync_ws2812_transfer();
 | 
			
		||||
 | 
			
		||||
    for (int i = 0; i < leds; i++) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -82,12 +82,6 @@ void ws2812_init(void) {
 | 
			
		|||
 | 
			
		||||
// Setleds for standard RGB
 | 
			
		||||
void ws2812_setleds(rgb_led_t *ledarray, uint16_t leds) {
 | 
			
		||||
    static bool s_init = false;
 | 
			
		||||
    if (!s_init) {
 | 
			
		||||
        ws2812_init();
 | 
			
		||||
        s_init = true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // this code is very time dependent, so we need to disable interrupts
 | 
			
		||||
    chSysLock();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -389,12 +389,6 @@ void ws2812_write_led_rgbw(uint16_t led_number, uint8_t r, uint8_t g, uint8_t b,
 | 
			
		|||
 | 
			
		||||
// Setleds for standard RGB
 | 
			
		||||
void ws2812_setleds(rgb_led_t* ledarray, uint16_t leds) {
 | 
			
		||||
    static bool s_init = false;
 | 
			
		||||
    if (!s_init) {
 | 
			
		||||
        ws2812_init();
 | 
			
		||||
        s_init = true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for (uint16_t i = 0; i < leds; i++) {
 | 
			
		||||
#ifdef RGBW
 | 
			
		||||
        ws2812_write_led_rgbw(i, ledarray[i].r, ledarray[i].g, ledarray[i].b, ledarray[i].w);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -188,12 +188,6 @@ void ws2812_init(void) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
void ws2812_setleds(rgb_led_t* ledarray, uint16_t leds) {
 | 
			
		||||
    static bool s_init = false;
 | 
			
		||||
    if (!s_init) {
 | 
			
		||||
        ws2812_init();
 | 
			
		||||
        s_init = true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for (uint8_t i = 0; i < leds; i++) {
 | 
			
		||||
        set_led_color_rgb(ledarray[i], i);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue