reduced DAC size

Speed-test
erikkaashoek 4 years ago
parent bce5d0dd42
commit c2fbf20eb7

@ -59,7 +59,7 @@
* @brief Enables the DAC subsystem. * @brief Enables the DAC subsystem.
*/ */
#if !defined(HAL_USE_DAC) || defined(__DOXYGEN__) #if !defined(HAL_USE_DAC) || defined(__DOXYGEN__)
#define HAL_USE_DAC TRUE #define HAL_USE_DAC FALSE
#endif #endif
/** /**

@ -1,5 +1,4 @@
/* /*
* Copyright (c) 2019-2020, written by DiSlord dislordlive@gmail.com
* All rights reserved. * All rights reserved.
* *
* This is free software; you can redistribute it and/or modify * This is free software; you can redistribute it and/or modify
@ -524,35 +523,23 @@ static const uint8_t ili9341_init_seq[] = {
#endif #endif
#ifdef __LCD_BRIGHTNESS__ #ifdef __LCD_BRIGHTNESS__
#if HAL_USE_DAC == FALSE #if HAL_USE_DAC == TRUE
#error "Need set HAL_USE_DAC in halconf.h for use __LCD_BRIGHTNESS__" #error "Need to disable HAL_USE_DAC in halconf.h for use __LCD_BRIGHTNESS__"
#endif #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_MIN_LEVEL 0
#define BRIGHTNESS_MAX_LEVEL 3300 #define BRIGHTNESS_MAX_LEVEL 4000
// Brightness control range 0 - 100 // Brightness control range 0 - 100
// DAC value range 0 - 4095 (0 to vRef in Volt)
void lcd_setBrightness(uint16_t b){ void lcd_setBrightness(uint16_t b){
b = BRIGHTNESS_MIN_LEVEL + b*((BRIGHTNESS_MAX_LEVEL-BRIGHTNESS_MIN_LEVEL)/100); b = BRIGHTNESS_MIN_LEVEL + b*((BRIGHTNESS_MAX_LEVEL-BRIGHTNESS_MIN_LEVEL)/100);
dacPutChannelX(&DACD2, 0, b); DAC->DHR12R2 = b;
} }
#else
#define lcd_initBrightness()
#endif #endif
void ili9341_init(void) void ili9341_init(void)
{ {
// Init Brightness if LCD support
lcd_initBrightness();
LCD_DC_DATA; LCD_DC_DATA;
LCD_RESET_ASSERT; LCD_RESET_ASSERT;
chThdSleepMilliseconds(10); chThdSleepMilliseconds(10);

@ -508,15 +508,15 @@ usage:
VNA_SHELL_FUNCTION(cmd_dac) VNA_SHELL_FUNCTION(cmd_dac)
{ {
int value; uint32_t value;
if (argc != 1) { if (argc != 1) {
shell_printf("usage: dac {value(0-4095)}\r\n"\ shell_printf("usage: dac {value(0-4095)}\r\n"\
"current value: %d\r\n", config.dac_value); "current value: %d\r\n", config.dac_value);
return; return;
} }
value = my_atoui(argv[0]); value = my_atoui(argv[0]) & 0xFFF;
config.dac_value = value; config.dac_value = value;
dacPutChannelX(&DACD2, 0, value); DAC->DHR12R2 = value;
} }
VNA_SHELL_FUNCTION(cmd_saveconfig) VNA_SHELL_FUNCTION(cmd_saveconfig)
@ -2284,11 +2284,6 @@ THD_FUNCTION(myshellThread, p)
} }
#endif #endif
static const DACConfig dac1cfg1 = {
init: 0,
datamode: DAC_DHRM_12BIT_RIGHT
};
#pragma GCC pop_options #pragma GCC pop_options
static const GPTConfig gpt4cfg = { 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: * 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 *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) int main(void)
{ {
@ -2463,13 +2461,14 @@ int main(void)
* Set LCD display brightness (use DAC2 for control) * Set LCD display brightness (use DAC2 for control)
* Starting DAC1 driver, setting up the output pin as analog as suggested by the Reference Manual. * 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__ #ifdef __LCD_BRIGHTNESS__
lcd_setBrightness(config._brightness); lcd_setBrightness(config._brightness);
#else #else
dacStart(&DACD2, &dac1cfg1); DAC->DHR12R2 = config.dac_value; // Setup DAC: CH2 value
dacPutChannelX(&DACD2, 0, config.dac_value);
#endif #endif
dacStart(&DACD1, &dac1cfg1); DAC->DHR12R1 = 0; // Setup DAC: CH1 value
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO-1, Thread1, NULL); chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO-1, Thread1, NULL);

@ -767,7 +767,7 @@ void SI4432_Listen(int s)
} else } else
count++; count++;
v = max - v; 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); } while(operation_requested == OP_NONE);
count = 0; count = 0;
// dacPutChannelX(&DACD1, 0, 0); // dacPutChannelX(&DACD1, 0, 0);

@ -1382,7 +1382,7 @@ void SI4432_Listen(int s)
} else } else
count++; count++;
v = max - v; 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); } while(operation_requested == OP_NONE);
count = 0; count = 0;
// dacPutChannelX(&DACD2, 0, 0); // dacPutChannelX(&DACD2, 0, 0);

Loading…
Cancel
Save

Powered by TurnKey Linux.