temp_sensor: temporarily add functions missing in the STM32L0 library

These functions are available in the libopencm3, but only for the
STM32F0. However, they should work with very little changes also for the
STM32L0, but have not been ported yet. Therefore I'm quickly testing
them here.
This commit is contained in:
Thomas Kolb 2023-09-29 22:07:05 +02:00
parent 938162bf5a
commit d526341b75
1 changed files with 55 additions and 1 deletions

View File

@ -72,7 +72,6 @@ static fxp_t calc_temperature_ntc(uint16_t adc_val)
return fxp_sub(temp_k, celsius2kelvin);
}
void temp_sensor_init(void)
{
uint8_t channels[ADC_NUM_CHANNELS] = {
@ -155,3 +154,58 @@ fxp_t temp_sensor_get_internal_temperature(void)
{
return m_temperature_internal;
}
// BEGIN temporary import from libopencm3
void adc_set_regular_sequence(uint32_t adc, uint8_t length, uint8_t channel[])
{
uint32_t reg32 = 0;
uint8_t i = 0;
bool stepup = false, stepdn = false;
if (length == 0) {
ADC_CHSELR(adc) = 0;
return;
}
reg32 |= (1 << channel[0]);
for (i = 1; i < length; i++) {
reg32 |= (1 << channel[i]);
stepup |= channel[i-1] < channel[i];
stepdn |= channel[i-1] > channel[i];
}
/* Check, if the channel list is in order */
if (stepup && stepdn) {
//cm3_assert_not_reached();
}
/* Update the scan direction flag */
if (stepdn) {
ADC_CFGR1(adc) |= ADC_CFGR1_SCANDIR;
} else {
ADC_CFGR1(adc) &= ~ADC_CFGR1_SCANDIR;
}
ADC_CHSELR(adc) = reg32;
}
/*---------------------------------------------------------------------------*/
/** @brief ADC Set the Sample Time for All Channels
*
* The sampling time can be selected in ADC clock cycles from 1.5 to 239.5,
* same for all channels.
*
* @param[in] adc Unsigned int32. ADC base address (@ref adc_reg_base)
* @param[in] time Unsigned int8. Sampling time selection (@ref adc_api_smptime)
*/
void adc_set_sample_time_on_all_channels(uint32_t adc, uint8_t time)
{
ADC_SMPR1(adc) = time;
}
// END temporary import from libopencm3