Skip to content
Snippets Groups Projects
Commit 2b1dc297 authored by Nicolò Caruso's avatar Nicolò Caruso
Browse files

[Driver] DipSwitch driver and test

[CI] Fixed CI, using namespace miosix was in DipSwitch.h

[ARP, LyraGS] Follower logging target angle. Dipswitch now agnostic.

Dipswitch now just read a uint8_t, no more has a lyra GS dependent read.
Follower now logging the target angle.

[DipSwitch] Fix on the test of the dipSwitch

Dipswitch now agnostic to the lyraGS struct, just a uint8_t read.
Fixed test to read accordingly.

[Fix] Dipswitch comment fix
parent 84ef1127
No related branches found
No related tags found
1 merge request!263[BSP, LyraGS, ARP] LyraGS BSP, Dipswitch driver and ARP-related algorithms
...@@ -109,7 +109,7 @@ add_executable(test-sensormanager src/tests/test-sensormanager.cpp) ...@@ -109,7 +109,7 @@ add_executable(test-sensormanager src/tests/test-sensormanager.cpp)
sbs_target(test-sensormanager stm32f429zi_death_stack_v2) sbs_target(test-sensormanager stm32f429zi_death_stack_v2)
add_executable(test-serial src/tests/test-serial.cpp) add_executable(test-serial src/tests/test-serial.cpp)
sbs_target(test-serial stm32f767zi_lyra_biscotto) sbs_target(test-serial stm32f767zi_lyra_gs)
add_executable(test-taskscheduler src/tests/scheduler/test-taskscheduler.cpp) add_executable(test-taskscheduler src/tests/scheduler/test-taskscheduler.cpp)
sbs_target(test-taskscheduler stm32f407vg_stm32f4discovery) sbs_target(test-taskscheduler stm32f407vg_stm32f4discovery)
...@@ -302,6 +302,9 @@ sbs_target(test-wiz5500 stm32f767zi_gemini_gs) ...@@ -302,6 +302,9 @@ sbs_target(test-wiz5500 stm32f767zi_gemini_gs)
add_executable(test-bsram src/tests/drivers/test-bsram.cpp) add_executable(test-bsram src/tests/drivers/test-bsram.cpp)
sbs_target(test-bsram stm32f767zi_lyra_biscotto) sbs_target(test-bsram stm32f767zi_lyra_biscotto)
add_executable(test-dipswitch src/tests/drivers/test-dipswitch.cpp)
sbs_target(test-dipswitch stm32f767zi_lyra_gs)
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
# Tests - Events # # Tests - Events #
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
......
...@@ -66,6 +66,7 @@ set(BOARDCORE_SRC ...@@ -66,6 +66,7 @@ set(BOARDCORE_SRC
${BOARDCORE_PATH}/src/shared/drivers/i2c/I2CDriver-f7.cpp ${BOARDCORE_PATH}/src/shared/drivers/i2c/I2CDriver-f7.cpp
${BOARDCORE_PATH}/src/shared/drivers/i2c/I2C.cpp ${BOARDCORE_PATH}/src/shared/drivers/i2c/I2C.cpp
${BOARDCORE_PATH}/src/shared/drivers/WIZ5500/WIZ5500.cpp ${BOARDCORE_PATH}/src/shared/drivers/WIZ5500/WIZ5500.cpp
${BOARDCORE_PATH}/src/shared/drivers/DipSwitch/DipSwitch.cpp
# Events # Events
${BOARDCORE_PATH}/src/shared/events/EventBroker.cpp ${BOARDCORE_PATH}/src/shared/events/EventBroker.cpp
......
...@@ -174,6 +174,10 @@ void Follower::step() ...@@ -174,6 +174,10 @@ void Follower::step()
state.verticalSpeed = verticalSpeed; state.verticalSpeed = verticalSpeed;
setState(state); setState(state);
// Log the target angles
Boardcore::Logger::getInstance().log(
static_cast<Boardcore::AntennaAngles>(targetAngles));
#ifndef NDEBUG #ifndef NDEBUG
std::cout << "[FOLLOWER] STEPPER " std::cout << "[FOLLOWER] STEPPER "
<< "Angles: [" << state.yaw << ", " << state.pitch << "] " << "Angles: [" << state.yaw << ", " << state.pitch << "] "
......
/* Copyright (c) 2024 Skyward Experimental Rocketry
* Author: Nicolò Caruso
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "DipSwitch.h"
uint8_t DipSwitch::read()
{
uint8_t read = 0;
// Write to the shift register (CS == Not LD)
sh.low();
miosix::delayUs(microSecClk);
clk.high();
miosix::delayUs(microSecClk);
sh.high();
miosix::delayUs(microSecClk);
// Read first register GS(0)/ARP(1)
read |= readBit();
read |= readBit() << 1;
read |= readBit() << 2;
read |= readBit() << 3;
read |= readBit() << 4;
read |= readBit() << 5;
read |= readBit() << 6;
read |= readBit() << 7;
return read;
}
uint8_t DipSwitch::readBit()
{
uint8_t bit;
clk.high();
miosix::delayUs(microSecClk);
bit = qh.value();
miosix::delayUs(microSecClk);
clk.low();
miosix::delayUs(microSecClk);
return bit;
}
\ No newline at end of file
/* Copyright (c) 2024 Skyward Experimental Rocketry
* Author: Nicolò Caruso
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <miosix.h>
/**
* @brief Dip switch driver to read the current status of the switch
*/
class DipSwitch
{
public:
DipSwitch(miosix::GpioPin& sh, miosix::GpioPin& clk, miosix::GpioPin& qh,
uint32_t microSecClk)
: sh{sh}, clk{clk}, qh{qh}, microSecClk{microSecClk}
{
}
/**
* @brief Performs a read of the dipSwitch
*
* @return uint8_t the read of the dip switch in big endian order. Dip 1 as
* most significant value, dip 8 as less significant.
* @note The order may depend on the dipswitch
* @note visually the order in a 8bit word is:
* dip order: [ 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 ]
* bits order: 12345678
*/
uint8_t read();
private:
miosix::GpioPin& sh;
miosix::GpioPin& clk;
miosix::GpioPin& qh;
uint32_t microSecClk;
/**
* @brief Reads a bit from the dip switch shift register
*/
uint8_t readBit();
};
\ No newline at end of file
/* Copyright (c) 2024 Skyward Experimental Rocketry
* Author: Nicolò Caruso
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <drivers/DipSwitch/DipSwitch.h>
#include <interfaces-impl/hwmapping.h>
#include <miosix.h>
using namespace miosix;
/**
* @brief Tests the read from a dipswitch using the DipSwitch driver
*/
int main()
{
uint32_t microSecClk = 100;
GpioPin sh = dipSwitch::sh::getPin();
GpioPin clk = dipSwitch::clk::getPin();
GpioPin qh = dipSwitch::qh::getPin();
DipSwitch dipSwitch(sh, clk, qh, microSecClk);
while (true)
{
uint8_t status;
Thread::sleep(1000);
status = dipSwitch.read();
printf("Read from dipSwitch: %d\n", status);
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment