Copyright 2023 Travis J. West, https://traviswest.ca, Input Devices and Music Interaction Laboratory (IDMIL), Centre for Interdisciplinary Research in Music Media and Technology (CIRMMT), McGill University, Montréal, Canada, and Univ. Lille, Inria, CNRS, Centrale Lille, UMR 9189 CRIStAL, F-59000 Lille, France
SPDX-License-Identifier: SPDX-License-Identifier: MIT
Oneshot analog-digital converter
#pragma once
#include "sygah-metadata.hpp"
#include "sygah-endpoints.hpp"
namespace sygaldry { namespace sygsr {
static constexpr unsigned int ADC_CHANNEL_0 = 0;
static constexpr unsigned int ADC_CHANNEL_1 = 1;
static constexpr unsigned int ADC_CHANNEL_2 = 2;
static constexpr unsigned int ADC_CHANNEL_3 = 3;
static constexpr unsigned int ADC_GPIO[] = {26,27,28,29};
template<unsigned int input_number>
struct OneshotAdc
: name_<"ADC">
, description_<"Oneshot analog-digital converter">
, author_<"Travis J. West">
, copyright_<"Copyright 2023 Sygaldry Contributors">
, license_<"SPDX-License-Identifier: MIT">
, version_<"0.0.0">
{
static_assert(ADC_CHANNEL_0 <= input_number && input_number <= ADC_CHANNEL_3);
struct outputs_t {
slider<"raw", "raw binary representation of the analog voltage measured by the ADC"
, int, 0, 4096, 0
> raw;
} outputs;
void init();
void main();
};
extern template struct OneshotAdc<ADC_CHANNEL_0>;
extern template struct OneshotAdc<ADC_CHANNEL_1>;
extern template struct OneshotAdc<ADC_CHANNEL_2>;
extern template struct OneshotAdc<ADC_CHANNEL_3>;
} }
#include "sygsr-adc.hpp"
#include <hardware/adc.h>
namespace sygaldry { namespace sygsr {
template<unsigned int input_num>
void OneshotAdc<input_num>::init()
{
adc_init();
adc_gpio_init(ADC_GPIO[input_num]);
}
template<unsigned int input_num>
void OneshotAdc<input_num>::main()
{
adc_select_input(input_num);
outputs.raw = (int)adc_read();
}
template struct OneshotAdc<ADC_CHANNEL_0>;
template struct OneshotAdc<ADC_CHANNEL_1>;
template struct OneshotAdc<ADC_CHANNEL_2>;
template struct OneshotAdc<ADC_CHANNEL_3>;
} }
#include <catch2/catch_test_macros.hpp>
#include "sygsr-adc.hpp"
using namespace sygaldry;
using namespace sygaldry::sygsr;
# @#'CMakeLists.txt'
set(lib sygsr-adc)
add_library(${lib} INTERFACE)
target_sources(${lib} INTERFACE ${lib}.cpp)
target_include_directories(${lib} INTERFACE .)
target_link_libraries(${lib}
INTERFACE sygah-endpoints
INTERFACE sygah-metadata
INTERFACE hardware_adc
)
if (SYGALDRY_BUILD_TESTS)
add_executable(${lib}-test ${lib}.test.cpp)
target_link_libraries(${lib}-test PRIVATE Catch2::Catch2WithMain)
target_link_libraries(${lib}-test PRIVATE ${lib})
#target_link_libraries(${lib}-test PRIVATE OTHERREQUIREDPACKAGESANDCOMPONENTSHERE)
catch_discover_tests(${lib}-test)
endif()
# @/