diff --git a/halconf.h b/halconf.h index 7077bb3..6f358e2 100644 --- a/halconf.h +++ b/halconf.h @@ -59,7 +59,7 @@ * @brief Enables the DAC subsystem. */ #if !defined(HAL_USE_DAC) || defined(__DOXYGEN__) -#define HAL_USE_DAC TRUE +#define HAL_USE_DAC FALSE #endif /** diff --git a/ili9341.c b/ili9341.c index c020681..3249d62 100644 --- a/ili9341.c +++ b/ili9341.c @@ -1,5 +1,4 @@ /* - * Copyright (c) 2019-2020, written by DiSlord dislordlive@gmail.com * All rights reserved. * * This is free software; you can redistribute it and/or modify @@ -524,35 +523,23 @@ static const uint8_t ili9341_init_seq[] = { #endif #ifdef __LCD_BRIGHTNESS__ -#if HAL_USE_DAC == FALSE -#error "Need set HAL_USE_DAC in halconf.h for use __LCD_BRIGHTNESS__" +#if HAL_USE_DAC == TRUE +#error "Need to disable HAL_USE_DAC in halconf.h for use __LCD_BRIGHTNESS__" #endif -static const DACConfig dac1cfg1 = { - init: 0, - datamode: DAC_DHRM_12BIT_RIGHT -}; - -static void lcd_initBrightness(void){ - dacStart(&DACD2, &dac1cfg1); -} #define BRIGHTNESS_MIN_LEVEL 0 -#define BRIGHTNESS_MAX_LEVEL 3300 +#define BRIGHTNESS_MAX_LEVEL 4000 // Brightness control range 0 - 100 +// DAC value range 0 - 4095 (0 to vRef in Volt) void lcd_setBrightness(uint16_t b){ b = BRIGHTNESS_MIN_LEVEL + b*((BRIGHTNESS_MAX_LEVEL-BRIGHTNESS_MIN_LEVEL)/100); - dacPutChannelX(&DACD2, 0, b); + DAC->DHR12R2 = b; } -#else -#define lcd_initBrightness() #endif void ili9341_init(void) { - // Init Brightness if LCD support - lcd_initBrightness(); - LCD_DC_DATA; LCD_RESET_ASSERT; chThdSleepMilliseconds(10); diff --git a/main.c b/main.c index b152f23..1a3944b 100644 --- a/main.c +++ b/main.c @@ -508,15 +508,15 @@ usage: VNA_SHELL_FUNCTION(cmd_dac) { - int value; + uint32_t value; if (argc != 1) { shell_printf("usage: dac {value(0-4095)}\r\n"\ "current value: %d\r\n", config.dac_value); return; } - value = my_atoui(argv[0]); + value = my_atoui(argv[0]) & 0xFFF; config.dac_value = value; - dacPutChannelX(&DACD2, 0, value); + DAC->DHR12R2 = value; } VNA_SHELL_FUNCTION(cmd_saveconfig) @@ -2284,11 +2284,6 @@ THD_FUNCTION(myshellThread, p) } #endif -static const DACConfig dac1cfg1 = { - init: 0, - datamode: DAC_DHRM_12BIT_RIGHT -}; - #pragma GCC pop_options static const GPTConfig gpt4cfg = { @@ -2310,6 +2305,9 @@ void my_microsecond_delay(int t) * Profile stack usage (enable threads command by def ENABLE_THREADS_COMMAND) show: *Stack maximum usage = 472 bytes (need test more and run all commands), free stack = 40 bytes */ +static void dac_init(void){ + rccEnableDAC1(false); // Enable DAC1 +} int main(void) { @@ -2463,13 +2461,14 @@ int main(void) * Set LCD display brightness (use DAC2 for control) * Starting DAC1 driver, setting up the output pin as analog as suggested by the Reference Manual. */ + dac_init(); + DAC->CR|= DAC_CR_EN1 | DAC_CR_EN2; // Use DAC: CH1 and CH2 #ifdef __LCD_BRIGHTNESS__ lcd_setBrightness(config._brightness); #else - dacStart(&DACD2, &dac1cfg1); - dacPutChannelX(&DACD2, 0, config.dac_value); + DAC->DHR12R2 = config.dac_value; // Setup DAC: CH2 value #endif - dacStart(&DACD1, &dac1cfg1); + DAC->DHR12R1 = 0; // Setup DAC: CH1 value chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO-1, Thread1, NULL); diff --git a/si4432.c b/si4432.c index 9af869b..40a91ba 100644 --- a/si4432.c +++ b/si4432.c @@ -767,7 +767,7 @@ void SI4432_Listen(int s) } else count++; v = max - v; - dacPutChannelX(&DACD1, 0, dBm_to_volt[v] << 4); + DAC->DHR12R1 = dBm_to_volt[v] << 4; // Use DAC: CH1 and put 12 bit right aligned value } while(operation_requested == OP_NONE); count = 0; // dacPutChannelX(&DACD1, 0, 0); diff --git a/si4468.c b/si4468.c index 974214d..c610e01 100644 --- a/si4468.c +++ b/si4468.c @@ -1382,7 +1382,7 @@ void SI4432_Listen(int s) } else count++; v = max - v; - dacPutChannelX(&DACD1, 0, dBm_to_volt[v] << 4); + DAC->DHR12R1 = dBm_to_volt[v] << 4; // Use DAC: CH1 and put 12 bit right aligned value } while(operation_requested == OP_NONE); count = 0; // dacPutChannelX(&DACD2, 0, 0);