38 lines
No EOL
842 B
C++
38 lines
No EOL
842 B
C++
#include <cmath>
|
|
|
|
#include "hardware/adc.h"
|
|
#include "pico/stdlib.h"
|
|
#include "tusb.h"
|
|
|
|
#include "utils.h"
|
|
|
|
uint8_t calcWPM(float percent, uint8_t wpmMin, uint8_t wpmMax)
|
|
{
|
|
auto wpm = (percent * (wpmMax - wpmMin) / 100) + wpmMin;
|
|
uint8_t result = static_cast<uint8_t>(std::round(wpm));
|
|
return result;
|
|
}
|
|
|
|
float potiRead()
|
|
{
|
|
// 12-bit conversion, assume max value == ADC_VREF == 3.3 V
|
|
const float conversion_factor = 3.3f / (1 << 12);
|
|
float voltage = adc_read() * conversion_factor;
|
|
|
|
return voltage * 100 / 3.3;
|
|
}
|
|
|
|
void usbSend(uint8_t itf, uint8_t buf[], uint32_t count)
|
|
{
|
|
for (uint32_t i = 0; i < count; i++) {
|
|
tud_cdc_n_write_char(itf, buf[i]);
|
|
}
|
|
|
|
tud_cdc_n_write_flush(itf);
|
|
}
|
|
|
|
void usbSend(uint8_t itf, uint8_t value)
|
|
{
|
|
tud_cdc_n_write_char(itf, value);
|
|
tud_cdc_n_write_flush(itf);
|
|
} |