summaryrefslogtreecommitdiff
path: root/Libraries/NixieDriver/nixie_driver_process.c
diff options
context:
space:
mode:
authorAlexander <trotsenkoa@gmail.com>2022-06-29 11:03:02 +0300
committerAlexander <trotsenkoa@gmail.com>2022-06-29 11:03:02 +0300
commit1702ce6ce430a66bb7af51644b91b7c196e719d9 (patch)
tree6039acbdf047873d32aaf55969286c5f0d55958f /Libraries/NixieDriver/nixie_driver_process.c
Создаю новый репозиторий. Программа для версии NixieClock_v2. Работает, часы тикают. Есть проблема, что скачет вторая сеносрная кнопка (она в другом канале). Поэтому на нее собираюсь сделать антидребезг.
Diffstat (limited to 'Libraries/NixieDriver/nixie_driver_process.c')
-rw-r--r--Libraries/NixieDriver/nixie_driver_process.c595
1 files changed, 595 insertions, 0 deletions
diff --git a/Libraries/NixieDriver/nixie_driver_process.c b/Libraries/NixieDriver/nixie_driver_process.c
new file mode 100644
index 0000000..ddc728b
--- /dev/null
+++ b/Libraries/NixieDriver/nixie_driver_process.c
@@ -0,0 +1,595 @@
+#include "nixie_driver_process.h"
+#include "nixie_driver_config.h"
+#include "indicate_modes_task.h"
+#include "light_sensor_task.h"
+
+#include <stdint.h>
+
+// FreeRTOS includes
+#include "FreeRTOS.h"
+#include "task.h"
+#include "queue.h"
+#include "semphr.h"
+
+// -
+// -
+// -
+// - 1
+// - 2
+
+#define TUBE_HEATING_UP 0
+
+
+static const uint16_t tube_off_digit = 0; // ,
+
+// . .
+// , 1
+const uint16_t tube_digits [MAX_DIGITS] = { //
+ TUBE_DIGIT_0, // 0
+ TUBE_DIGIT_1, // 1
+ TUBE_DIGIT_2, // 2
+ TUBE_DIGIT_3, // 3
+ TUBE_DIGIT_4, // 4
+ TUBE_DIGIT_5, // 5
+ TUBE_DIGIT_6, // 6
+ TUBE_DIGIT_7, // 7
+ TUBE_DIGIT_8, // 8
+ TUBE_DIGIT_9, // 9
+ TUBE_DIGIT_DP1, // dp1
+ TUBE_DIGIT_DP2, // dp2
+ TUBE_DIGIT_EMPTY //
+};
+
+// . ,
+// SPI
+// , 1
+static const uint16_t tube_num [ MAX_TUBES ] = {
+ TUBE_NUM_1, // 1-
+ TUBE_NUM_2, // 2-
+ TUBE_NUM_3, // 3-
+ TUBE_NUM_4, // 4-
+ TUBE_NUM_5, // 5-
+ TUBE_NUM_6 // 6-
+};
+
+
+// -
+static uint16_t curr_tube_bufer [ MAX_TUBES ] = {
+ TUBE_DIGIT_1, // 0
+ TUBE_DIGIT_1, // 1
+ TUBE_DIGIT_1, // 2
+ TUBE_DIGIT_1, // 3
+ TUBE_DIGIT_1, // 4
+ TUBE_DIGIT_1 // 5
+};
+
+
+// ------------------------------------------------------------------ //
+
+// /
+// time1 / time2
+// 1 9
+// 2 8
+// 3 7
+// 4 6
+// 5 6
+// 6 4
+// 7 3
+// 8 2
+// 9 1
+// 10 0
+
+#define TIME_PERIOD_TCONST (uint32_t)80 // .
+ // . 100 , = 80 => T = 80*100 = 8000 = 8
+#define TIME_MIN (uint32_t)1 // = 100 .
+
+// - DARK LIGHT
+// ( TIME_ON TIME_OFF)
+#define TIME_ON 2//5//20
+#define TIME_OFF 23//22
+// /
+#define TIME_OFF_BRIGHT 0
+#define TIME_OFF_DARK 100
+
+#define TIME_TEST 10000
+
+static uint32_t time_on = TIME_ON; //
+static uint32_t time_off = TIME_OFF; // ( )
+static uint32_t time_off2 = TIME_OFF_DARK;
+// static uint32_t time_on = TIME_OFF;
+// static uint32_t time_off = TIME_ON;
+// static uint32_t time_off2 = TIME_OFF_BRIGHT;
+
+//static uint32_t coef_brightness = 1; // . !
+
+//
+// .. 2 .
+//static uint8_t first_byte;
+
+//
+//static uint16_t tube_nbr_second_value;
+
+//
+QueueHandle_t queue_new_value;
+QueueHandle_t queue_new_data;
+static LightSensorState_t light_sensor_state;
+extern QueueHandle_t queue_light_sensor;
+
+
+// -------------------------------------------------- //
+//
+void NixieDriver_SendValue ( uint8_t *value_arr );
+//
+static void SwitchOnTube ( uint8_t tube_nbr );
+static void SwitchOffTube ( uint8_t tube_nbr );
+// - ( EE )
+// void NixieDriver_LoadBrightnessFromMemory ( void ); // - coef_brightness
+//static void NewTimeCalculate ( uint32_t *time_on, uint32_t *time_off );
+// - - NixieDriver_SetBrightness ( uint32_t ??? ); // ?
+// - - NixieDriver_IncreaseBrighntness ( void ); // ( . +1 )
+// - - NixieDriver_DecreaseBrighntness ( void ); // ( . -1 )
+
+#if TUBE_HEATING_UP == 0
+static uint8_t LoadNextValueToTubes ( void );
+#else
+static uint8_t LoadNextValueToTubes ( void );
+#endif
+
+//static void TestLoadNewValueToClock ( void );
+static void UpdateValueForClock ( void );
+static void CheckLightSensor (void);
+
+
+// ----------------------------------------------------------------------------
+//
+// ----------------------------------------------------------------------------
+void NixieDriverInitProcess ( void )
+{
+ //first_byte = 0;
+
+ queue_new_value = xQueueCreate ( 1, sizeof (uint8_t*) );
+ configASSERT( queue_new_value );
+ queue_new_data = xQueueCreate ( 1, sizeof (DataToIndicate_t) );
+ configASSERT( queue_new_value );
+}
+
+
+// ----------------------------------------------------------------------------
+// -, Nixie
+// - , 100
+// ----------------------------------------------------------------------------
+void ProcessNixieDriverFromISR ( void )
+{
+ static uint8_t process_indic_state = 0;
+ static uint32_t timer = TIME_ON;
+ static uint8_t curr_tube_num = 0;
+
+ timer++;
+ //timer_test++;
+
+#if TUBE_HEATING_UP == 0
+
+ switch ( process_indic_state )
+ {
+
+ case 0:
+
+ if ( timer >= time_off ) //
+ {
+ curr_tube_num = LoadNextValueToTubes ();
+ SwitchOnTube ( curr_tube_num );
+ timer = 0;
+ process_indic_state = 1;
+ /*
+ if ( curr_tube_num == (MAX_TUBES - 1) )
+ {
+ UpdateValueForClock ();
+ CheckLightSensor();
+
+ // SwitchOffTube ( curr_tube_num );
+ //process_indic_state = 2;
+ //timer = 0;
+
+ }
+ */
+ }
+
+ break;
+
+ case 1:
+
+ if ( timer >= time_on )
+ {
+ SwitchOffTube ( curr_tube_num );
+ timer = 0;
+ process_indic_state = 0;
+
+ if ( curr_tube_num == (MAX_TUBES - 1) )
+ {
+ UpdateValueForClock ();
+ CheckLightSensor();
+
+ SwitchOffTube ( curr_tube_num );
+ process_indic_state = 2;
+ timer = 0;
+
+ }
+ }
+
+ break;
+
+ case 2:
+
+ if ( timer >= time_off2 )
+ {
+ //SwitchOnTube ( curr_tube_num );
+ timer = time_off;
+ process_indic_state = 0;
+ }
+
+ break;
+
+ } // end switch
+
+#else
+/*
+ switch ( process_indic_state )
+ {
+
+ case 0:
+
+ SwitchOnTube ( curr_tube_num );
+ timer = 0;
+ process_indic_state = 1;
+
+ break;
+
+ case 1:
+
+ if ( timer >= time1 ) //
+ {
+ curr_tube_num = LoadNextValueToTubes ();
+ timer = 0;
+ process_indic_state = 0;
+ }
+
+ break;
+
+ } // end switch
+ */
+
+#endif
+
+}
+
+// ----------------------------------------------------------------------------
+// - SPI
+// .
+// - ,
+// -
+// ----------------------------------------------------------------------------
+static void SwitchOnTube ( uint8_t tube_nbr )
+{
+ // -
+ // -
+
+ static uint16_t temp;
+
+ temp = 0;
+ temp = tube_num [ tube_nbr ]; //(uint16_t)curr_tube_bufer [ tube_nbr ];
+ temp |= curr_tube_bufer [ tube_nbr ];
+
+ NIX_DRIVER_RESET_ST_PIN;
+
+ // .. GPIO,
+ //
+ // :
+ // , SPI,
+ // , ST
+ if (curr_tube_bufer [ tube_nbr ] & TUBE_DIGIT_DP1)
+ {
+ NIX_DRIVER_SET_TUB_DP1_PIN;
+ }
+ else
+ {
+ NIX_DRIVER_RESET_TUB_DP1_PIN;
+ }
+
+ if (curr_tube_bufer [ tube_nbr ] & TUBE_DIGIT_DP2)
+ {
+ NIX_DRIVER_SET_TUB_DP2_PIN;
+ }
+ else
+ {
+ NIX_DRIVER_RESET_TUB_DP2_PIN;
+ }
+
+ SPI_I2S_SendData16 ( NIX_SPIx, temp );
+ SPI_I2S_ITConfig ( NIX_SPIx, SPI_I2S_IT_TXE, ENABLE );
+}
+
+
+// ----------------------------------------------------------------------------
+// -
+// ----------------------------------------------------------------------------
+static void SwitchOffTube ( uint8_t tube_nbr )
+{
+ //static uint16_t value_to_spi1;
+ //static uint16_t temp1;
+
+ //value_to_spi1 = (uint16_t)tube_off_digit;
+ //value_to_spi1 <<= 8;
+
+ //temp1 = 0;
+ //temp1 = (uint16_t)tube_num [ tube_nbr ];
+
+ //value_to_spi1 |= temp1;
+
+ //first_byte = 1;
+ //tube_nbr_second_value = tube_off_digit;
+ NIX_DRIVER_RESET_ST_PIN;
+
+ NIX_DRIVER_RESET_TUB_DP1_PIN;
+ NIX_DRIVER_RESET_TUB_DP2_PIN;
+ SPI_I2S_SendData16 ( NIX_SPIx, tube_off_digit );
+ SPI_I2S_ITConfig ( NIX_SPIx, SPI_I2S_IT_TXE, ENABLE );
+}
+
+// ----------------------------------------------------------------------------
+// -
+// SPI
+// - SPI
+// , GPIO
+// ----------------------------------------------------------------------------
+// void NixieDriverCheckDPPins (void)
+// {
+// ;
+// }
+
+
+// ----------------------------------------------------------------------------
+// - 2 SPI
+// - NIX_SPIx_IRQHandler
+// ----------------------------------------------------------------------------
+// uint8_t NixieDriverProcessCheckIsFirstByte (void)
+// {
+// //return first_byte;
+// return 0;
+// }
+
+
+// ----------------------------------------------------------------------------
+// -
+// ----------------------------------------------------------------------------
+// void NixieDriverProcessSendSecondByte ( void )
+// {
+// first_byte = 0;
+// SPI_I2S_SendData16 ( NIX_SPIx, tube_nbr_second_value );
+// }
+
+
+#if TUBE_HEATING_UP == 1
+// ----------------------------------------------------------------------------
+// -
+// ----------------------------------------------------------------------------
+static uint8_t LoadNextValueToTubes ( void )
+{
+ static uint8_t curr_tube_num = 0;
+ static uint8_t curr_digit = 0;
+
+ if ( curr_digit == 10 )
+ {
+ if ( curr_tube_num == 5 )
+ {
+ curr_tube_num = 0;
+ }
+ else
+ {
+ curr_tube_num++;
+ if ( curr_tube_num == 1 ) { curr_tube_num++; }
+ }
+ curr_digit = 0;
+ }
+
+ curr_tube_bufer [ curr_tube_num ] = tube_digits [ curr_digit ];
+ curr_digit++;
+
+ return curr_tube_num;
+}
+
+#else
+
+static uint8_t LoadNextValueToTubes ( void )
+{
+ static uint8_t curr_tube_num = 5;
+
+ if ( curr_tube_num == 5 )
+ {
+ curr_tube_num = 0;
+ //NIX_TEST_PIN_PB11_TOGGLE;
+ }
+ else
+ {
+ curr_tube_num++;
+ }
+
+ return curr_tube_num;
+}
+
+#endif
+
+
+// ----------------------------------------------------------------------------
+// -
+//
+// ----------------------------------------------------------------------------
+//static void NewTimeCalculate ( uint32_t *time_on, uint32_t *time_off )
+//{
+//// uint32_t time_check;
+////
+//// time_on = TIME_MIN*coef_brightness;
+////
+//// if ( time_on > TIME_PERIOD_TCONST ) { return; }
+//
+//}
+
+
+// ----------------------------------------------------------------------------
+// -
+//
+// ----------------------------------------------------------------------------
+//static void TestLoadNewValueToClock ( void )
+//{
+// static uint8_t digit_num = 0;
+//
+// //curr_tube_bufer [] = tube_digits [];
+// //
+// for ( uint8_t tube_num = 0; tube_num < MAX_TUBES; tube_num++ )
+// {
+// curr_tube_bufer [tube_num] = tube_digits [digit_num];
+// }
+// digit_num++;
+//
+// if ( digit_num == MAX_DIGITS )
+// {
+// digit_num = 0;
+// }
+//}
+
+
+// ----------------------------------------------------------------------------
+//
+// - - ProcessNixieDriverFromISR ()
+// ( 6- )
+// ----------------------------------------------------------------------------
+
+// - ! ,
+// SPI. ,
+// . .
+// , .
+// , .
+
+// - tube_digits [10]
+// ( 10)
+
+static void UpdateValueForClock ( void )
+{
+ // -
+ // , curr_tube_bufer []
+ //uint8_t *value_arr;
+ DataToIndicate_t data_struct;
+
+// if ( pdPASS == xQueueReceive ( queue_new_value, &value_arr, 0 ) )
+// {
+// for ( uint8_t tube_num = 0; tube_num < MAX_TUBES; tube_num++ )
+// {
+// curr_tube_bufer [tube_num] = tube_digits [ value_arr [tube_num] ];
+// }
+// }
+
+
+ if ( pdPASS == xQueueReceive ( queue_new_data, &data_struct, 0 ) )
+ {
+ curr_tube_bufer [0] = tube_digits [ data_struct.indic_1 ];
+ curr_tube_bufer [1] = tube_digits [ data_struct.indic_2 ];
+ curr_tube_bufer [2] = tube_digits [ data_struct.indic_3 ];
+ curr_tube_bufer [3] = tube_digits [ data_struct.indic_4 ];
+ curr_tube_bufer [4] = tube_digits [ data_struct.indic_5 ];
+ curr_tube_bufer [5] = tube_digits [ data_struct.indic_6 ];
+
+ }
+
+}
+
+
+// ----------------------------------------------------------------------------
+//
+// ----------------------------------------------------------------------------
+static void CheckLightSensor (void)
+{
+ //LightSensorState_t light_sensor_state;
+ if ( pdPASS == xQueueReceive ( queue_light_sensor, &light_sensor_state, 0 ) )
+ {
+ if (light_sensor_state == LIGHT_SENSOR_STATE_LIGHT )
+ {
+ time_on = TIME_OFF;
+ time_off = TIME_ON;
+ time_off2 = TIME_OFF_BRIGHT;//TIME_OFF_DARK;
+ }
+ else
+ {
+ time_on = TIME_ON;
+ time_off = TIME_OFF;
+ time_off2 = TIME_OFF_DARK;//TIME_OFF_BRIGHT;
+ }
+ }
+}
+
+
+// ----------------------------------------------------------------------------
+// -
+// 6 ( )
+// ----------------------------------------------------------------------------
+void NixieDriver_SendValue ( uint8_t *value_arr )
+{
+ xQueueSend ( queue_new_value, &value_arr, 0 );
+}
+
+//void NixieDriver_SendValue2 ( uint8_t *value_arr )
+//{
+// xQueueSend ( queue_new_value, &value_arr, 0 );
+//}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+