forked from j3d1/fiatlux
		
	keep refactoring
This commit is contained in:
		
							parent
							
								
									d75262dbea
								
							
						
					
					
						commit
						8ffae0b66f
					
				
					 3 changed files with 115 additions and 88 deletions
				
			
		|  | @ -18,90 +18,8 @@ | |||
| #include "wifi.h" | ||||
| #include "web.h" | ||||
| #include "mqtt.h" | ||||
| #include "lux.h" | ||||
| 
 | ||||
| const int cs0 = 15; | ||||
| const int gpio4 = 4; | ||||
| const int gpio5 = 5; | ||||
| 
 | ||||
| const int led_number = 8; | ||||
| 
 | ||||
| static ws2812_pixel_t next_colour(int i) { | ||||
|     ws2812_pixel_t colour = {{0, 0, 0, 0}}; | ||||
|     if(i == 8) { | ||||
|         colour.white = 32; | ||||
|     } else { | ||||
|         colour.red = i & 1 ? 32 : 0; | ||||
|         colour.green = i & 2 ? 32 : 0; | ||||
|         colour.blue = i & 4 ? 32 : 0; | ||||
|     } | ||||
| 
 | ||||
|     return colour; | ||||
| } | ||||
| 
 | ||||
| void spi_dac(int id, int val) { | ||||
|     int dac_val = (val << 2) & 0x3FFC; | ||||
| 
 | ||||
|     spi_transfer_8(1, ~(0x00)); | ||||
|     gpio_write(cs0, 1); | ||||
|     gpio_write(cs0, 0); | ||||
|     spi_transfer_8(1, ~(0x01 << id)); | ||||
|     gpio_write(cs0, 1); | ||||
|     gpio_write(cs0, 0); | ||||
| 
 | ||||
|     spi_transfer_16(1, dac_val); | ||||
| 
 | ||||
|     spi_transfer_8(1, ~(0x00)); | ||||
|     gpio_write(cs0, 1); | ||||
|     gpio_write(cs0, 0); | ||||
|     spi_transfer_8(1, ~(0x01 << id)); | ||||
|     gpio_write(cs0, 1); | ||||
|     gpio_write(cs0, 0); | ||||
| } | ||||
| 
 | ||||
| /* This task uses the high level GPIO API (esp_gpio.h) to blink an LED.
 | ||||
|  * | ||||
|  */ | ||||
| void blinkenTask(void *pvParameters) { | ||||
| 
 | ||||
|     gpio_enable(9, GPIO_INPUT); | ||||
|     gpio_enable(10, GPIO_INPUT); | ||||
| 
 | ||||
|     ws2812_pixel_t pixels[led_number]; | ||||
|     ws2812_i2s_init(led_number, PIXEL_RGBW); | ||||
|     memset(pixels, 0, sizeof(ws2812_pixel_t) * led_number); | ||||
| 
 | ||||
|     gpio_enable(cs0, GPIO_OUTPUT); | ||||
|     gpio_enable(gpio4, GPIO_OUTPUT); | ||||
|     gpio_enable(gpio5, GPIO_OUTPUT); | ||||
|     spi_init(1, SPI_MODE0, SPI_FREQ_DIV_1M, 1, SPI_BIG_ENDIAN, 1); | ||||
|     while (1) { | ||||
|         gpio_write(gpio4, 1); | ||||
|         vTaskDelay(200 / portTICK_PERIOD_MS); | ||||
|         gpio_write(gpio4, 0); | ||||
|         for (int j = 0; j < 64; j++) { | ||||
|             for (int i = 0; i < 8; i++) | ||||
|                 spi_dac(i, 64 * j); | ||||
|             //printf("> %d\n", 64*j);
 | ||||
|             vTaskDelay(1000 / portTICK_PERIOD_MS); | ||||
|         } | ||||
|         for (int i = 0; i < 8; i++) | ||||
|             spi_dac(i, 0); | ||||
| 
 | ||||
|         gpio_write(gpio5, 1); | ||||
|         vTaskDelay(200 / portTICK_PERIOD_MS); | ||||
|         gpio_write(gpio5, 0); | ||||
| 
 | ||||
|         for (int c = 8; c >= 0; c--) { | ||||
| 
 | ||||
|             for (int i = 0; i < led_number; i++) { | ||||
|                 pixels[i] = next_colour(c); | ||||
|             } | ||||
|             ws2812_i2s_update(pixels, PIXEL_RGBW); | ||||
|             vTaskDelay(200 / portTICK_PERIOD_MS); | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| #define SNTP_SERVERS     "0.pool.ntp.org", "1.pool.ntp.org", \ | ||||
|                         "2.pool.ntp.org", "3.pool.ntp.org" | ||||
|  | @ -112,9 +30,6 @@ void blinkenTask(void *pvParameters) { | |||
| const gpio_inttype_t int_type = GPIO_INTTYPE_EDGE_NEG; | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| void sntp_task(void *pvParameters) { | ||||
|     const char *servers[] = {SNTP_SERVERS}; | ||||
|     UNUSED_ARG(pvParameters); | ||||
|  | @ -487,10 +402,10 @@ void user_init(void) { | |||
|         /* turn off LED */ | ||||
|         //gpio_enable(LED_PIN, GPIO_OUTPUT);
 | ||||
|         //gpio_write(LED_PIN, true);
 | ||||
|         xTaskCreate(blinkenTask, "blinkenTask", 256, NULL, 2, NULL); | ||||
|         xTaskCreate(&lux_task, "lux_task", 256, NULL, 2, NULL); | ||||
| 
 | ||||
|         /* initialize tasks */ | ||||
|         xTaskCreate(&httpd_task, "HTTP Daemon", 2048, NULL, 2, NULL); | ||||
|         xTaskCreate(&httpd_task, "&httpd_task", 2048, NULL, 2, NULL); | ||||
| 
 | ||||
|         xTaskCreate(&sntp_task, "SNTP", 512, NULL, 1, NULL); | ||||
|     } | ||||
|  |  | |||
							
								
								
									
										100
									
								
								firmware/lux.cpp
									
										
									
									
									
								
							
							
						
						
									
										100
									
								
								firmware/lux.cpp
									
										
									
									
									
								
							|  | @ -1,3 +1,103 @@ | |||
| //
 | ||||
| // Created by jedi on 25.06.21.
 | ||||
| //
 | ||||
| <<<<<<< HEAD | ||||
| ======= | ||||
| 
 | ||||
| #include "lux.h" | ||||
| 
 | ||||
| #include <string.h> | ||||
| #include <FreeRTOS.h> | ||||
| #include <task.h> | ||||
| 
 | ||||
| #include <esp/spi.h> | ||||
| #include <ws2812_i2s/ws2812_i2s.h> | ||||
| 
 | ||||
| 
 | ||||
| const int LED_PIN = 2; | ||||
| const int SWITCH_PIN = 2; | ||||
| 
 | ||||
| const int cs0 = 15; | ||||
| const int gpio4 = 4; | ||||
| const int gpio5 = 5; | ||||
| 
 | ||||
| static ws2812_pixel_t next_colour(int i) { | ||||
|     ws2812_pixel_t colour = {{0, 0, 0, 0}}; | ||||
|     if(i == 8) { | ||||
|         colour.white = 32; | ||||
|     } else { | ||||
|         colour.red = i & 1 ? 32 : 0; | ||||
|         colour.green = i & 2 ? 32 : 0; | ||||
|         colour.blue = i & 4 ? 32 : 0; | ||||
|     } | ||||
| 
 | ||||
|     return colour; | ||||
| } | ||||
| 
 | ||||
| void spi_dac(int id, int val) { | ||||
|     int dac_val = (val << 2) & 0x3FFC; | ||||
| 
 | ||||
|     spi_transfer_8(1, ~(0x00)); | ||||
|     gpio_write(cs0, 1); | ||||
|     gpio_write(cs0, 0); | ||||
|     spi_transfer_8(1, ~(0x01 << id)); | ||||
|     gpio_write(cs0, 1); | ||||
|     gpio_write(cs0, 0); | ||||
| 
 | ||||
|     spi_transfer_16(1, dac_val); | ||||
| 
 | ||||
|     spi_transfer_8(1, ~(0x00)); | ||||
|     gpio_write(cs0, 1); | ||||
|     gpio_write(cs0, 0); | ||||
|     spi_transfer_8(1, ~(0x01 << id)); | ||||
|     gpio_write(cs0, 1); | ||||
|     gpio_write(cs0, 0); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /* This task uses the high level GPIO API (esp_gpio.h) to blink an LED.
 | ||||
|  * | ||||
|  */ | ||||
| extern "C" void lux_task(void *pvParameters) { | ||||
| 
 | ||||
|     gpio_enable(9, GPIO_INPUT); | ||||
|     gpio_enable(10, GPIO_INPUT); | ||||
| 
 | ||||
|     ws2812_pixel_t pixels[led_number]; | ||||
|     ws2812_i2s_init(led_number, PIXEL_RGBW); | ||||
|     memset(pixels, 0, sizeof(ws2812_pixel_t) * led_number); | ||||
| 
 | ||||
|     gpio_enable(cs0, GPIO_OUTPUT); | ||||
|     gpio_enable(gpio4, GPIO_OUTPUT); | ||||
|     gpio_enable(gpio5, GPIO_OUTPUT); | ||||
|     spi_init(1, SPI_MODE0, SPI_FREQ_DIV_1M, 1, SPI_BIG_ENDIAN, 1); | ||||
|     while (1) { | ||||
|         gpio_write(gpio4, 1); | ||||
|         vTaskDelay(200 / portTICK_PERIOD_MS); | ||||
|         gpio_write(gpio4, 0); | ||||
|         for (int j = 0; j < 64; j++) { | ||||
|             for (int i = 0; i < 8; i++) | ||||
|                 spi_dac(i, 64 * j); | ||||
|             //printf("> %d\n", 64*j);
 | ||||
|             vTaskDelay(1000 / portTICK_PERIOD_MS); | ||||
|         } | ||||
|         for (int i = 0; i < 8; i++) | ||||
|             spi_dac(i, 0); | ||||
| 
 | ||||
|         gpio_write(gpio5, 1); | ||||
|         vTaskDelay(200 / portTICK_PERIOD_MS); | ||||
|         gpio_write(gpio5, 0); | ||||
| 
 | ||||
|         for (int c = 8; c >= 0; c--) { | ||||
| 
 | ||||
|             for (int i = 0; i < led_number; i++) { | ||||
|                 pixels[i] = next_colour(c); | ||||
|             } | ||||
|             ws2812_i2s_update(pixels, PIXEL_RGBW); | ||||
|             vTaskDelay(200 / portTICK_PERIOD_MS); | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| } | ||||
| >>>>>>> 8d3006e (keep refactoring) | ||||
|  |  | |||
|  | @ -6,9 +6,21 @@ | |||
| #define FIRMWARE_LUX_H | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| <<<<<<< HEAD | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| ======= | ||||
| constexpr int led_number = 8; | ||||
| #endif | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| void lux_task(void *pvParameters); | ||||
| 
 | ||||
| >>>>>>> 8d3006e (keep refactoring) | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue