Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mmyster/feature/lk quad digital to analog converter #940

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions spikes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ add_subdirectory(${SPIKES_DIR}/lk_lcd)
add_subdirectory(${SPIKES_DIR}/lk_led_kit)
add_subdirectory(${SPIKES_DIR}/lk_log_kit)
add_subdirectory(${SPIKES_DIR}/lk_motors)
add_subdirectory(${SPIKES_DIR}/lk_qdac)
add_subdirectory(${SPIKES_DIR}/lk_reinforcer)
add_subdirectory(${SPIKES_DIR}/lk_rfid)
add_subdirectory(${SPIKES_DIR}/lk_sensors_battery)
Expand Down Expand Up @@ -56,6 +57,7 @@ add_dependencies(spikes_leka
spike_lk_led_kit
spike_lk_log_kit
spike_lk_motors
spike_lk_qdac
spike_lk_reinforcer
spike_lk_rfid
spike_lk_sensors_battery
Expand Down
22 changes: 22 additions & 0 deletions spikes/lk_qdac/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Leka - LekaOS
# Copyright 2022 APF France handicap
# SPDX-License-Identifier: Apache-2.0

add_mbed_executable(spike_lk_qdac)

target_include_directories(spike_lk_qdac
PRIVATE
.
)

target_sources(spike_lk_qdac
PRIVATE
main.cpp
)

target_link_libraries(spike_lk_qdac
CoreI2C
CoreQDAC
)

target_link_custom_leka_targets(spike_lk_qdac)
76 changes: 76 additions & 0 deletions spikes/lk_qdac/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Leka - LekaOS
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#include "PinNames.h"

#include "drivers/HighResClock.h"
#include "rtos/ThisThread.h"

#include "CoreI2C.h"
#include "CoreQDAC.h"
#include "HelloWorld.h"
#include "LogKit.h"

using namespace leka;
using namespace std::chrono;

//
// MARK: - Global definitions
//

auto corei2c = CoreI2C {PinName::SENSOR_PROXIMITY_MUX_I2C_SDA, PinName::SENSOR_PROXIMITY_MUX_I2C_SCL};
auto dac = CoreQDACMCP4728 {corei2c, 0xC2};

auto data = uint16_t {};

void printInputRegisters()
{
for (auto channels = std::array<uint8_t, 4> {mcp4728::channel::A, mcp4728::channel::B, mcp4728::channel::C,
mcp4728::channel::D};
uint8_t channel: channels) {
log_info("================= Channel %d ================= ", channel);
data = dac.read(channel);
log_info("Input Registers === Data: %x", data);
log_info("\n\n");
}
}

auto main() -> int
{
logger::init();

log_info("Hello, World!\n\n");

HelloWorld hello;
hello.start();

rtos::ThisThread::sleep_for(1s);

auto channel = uint8_t {};
log_info("Read DAC (channel 0=A, 1=B, 2=C, 3=D):\n");

log_info("Init !\n");
dac.init();
rtos::ThisThread::sleep_for(100ms);
printInputRegisters();
rtos::ThisThread::sleep_for(2s);

channel = 0x00;

data = 0x0ABC;
log_info("Writing ! Channel : %d, Data : %x\n", channel, data);
dac.write(channel, data);
rtos::ThisThread::sleep_for(100ms);
printInputRegisters();
rtos::ThisThread::sleep_for(1s);

channel = 0x01;

data = 0x0DEF;
log_info("Writing ! Channel : %d, Data : %x\n", channel, data);
dac.write(channel, data);
rtos::ThisThread::sleep_for(100ms);
printInputRegisters();
rtos::ThisThread::sleep_for(1s);
}