Skip to content

Commit

Permalink
Issue #25 : Add wider API support of RasPi Pico SDK
Browse files Browse the repository at this point in the history
hardware_rtc.
  • Loading branch information
suikan4github committed Dec 4, 2024
1 parent 0be7910 commit 181ea7b
Show file tree
Hide file tree
Showing 11 changed files with 668 additions and 31 deletions.
26 changes: 26 additions & 0 deletions src/sdk/mocksdkwrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,32 @@ class MockSdkWrapper : public SdkWrapper {
MOCK_METHOD0(sha256_start, void());
MOCK_METHOD0(sha256_wait_ready_blocking, void());
MOCK_METHOD0(sha256_wait_valid_blocking, void());
MOCK_METHOD1(spi_deinit, void(spi_inst_t* spi));
MOCK_METHOD1(spi_get_baudrate, uint(const spi_inst_t* spi));
MOCK_METHOD1(spi_get_const_hw, const spi_hw_t*(const spi_inst_t* spi));
MOCK_METHOD2(spi_get_dreq, uint(spi_inst_t* spi, bool is_tx));
MOCK_METHOD1(spi_get_hw, spi_hw_t*(spi_inst_t* spi));
MOCK_METHOD1(spi_get_index, uint(const spi_inst_t* spi));
MOCK_METHOD2(spi_init, uint(spi_inst_t* spi, uint baudrate));
MOCK_METHOD1(spi_is_busy, bool(const spi_inst_t* spi));
MOCK_METHOD1(spi_is_readable, bool(const spi_inst_t* spi));
MOCK_METHOD1(spi_is_writable, bool(const spi_inst_t* spi));
MOCK_METHOD4(spi_read16_blocking,
int(spi_inst_t* spi, uint16_t repeated_tx_data, uint16_t* dst,
size_t len));
MOCK_METHOD4(spi_read_blocking, int(spi_inst_t* spi, uint8_t repeated_tx_data,
uint8_t* dst, size_t len));
MOCK_METHOD2(spi_set_baudrate, uint(spi_inst_t* spi, uint baudrate));
MOCK_METHOD2(spi_set_slave, void(spi_inst_t* spi, bool slave));
MOCK_METHOD3(spi_write16_blocking,
int(spi_inst_t* spi, const uint16_t* src, size_t len));
MOCK_METHOD4(spi_write16_read16_blocking,
int(spi_inst_t* spi, const uint16_t* src, uint16_t* dst,
size_t len));
MOCK_METHOD3(spi_write_blocking,
int(spi_inst_t* spi, const uint8_t* src, size_t len));
MOCK_METHOD4(spi_write_read_blocking, int(spi_inst_t* spi, const uint8_t* src,
uint8_t* dst, size_t len));
} // class MockSdkWrapper : public SdkWrapper
;
// GCOVR_EXCL_STOP
Expand Down
4 changes: 4 additions & 0 deletions src/sdk/pico_api_alternate_defs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ enum pwm_clkdiv_mode { q, r };
/// @brief Alternate definition for Google Test build.
enum sha256_endianness { s, t };

//// @brief Alternate definition for Google Test build.
typedef int spi_inst_t;
//// @brief Alternate definition for Google Test build.
typedef int spi_hw_t;
//// @brief Alternate definition for Google Test build.
typedef int sha256_result_t;
//// @brief Alternate definition for Google Test build.
Expand Down
411 changes: 411 additions & 0 deletions src/sdk/pico_sdk_apistub.cpp

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/sdk/pico_sdk_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,7 @@
#include <hardware/sha256.h>
#endif // __has_include(<hardware/sha256.h>) || __has_include(<gmock/gmock.h>)

#if __has_include(<hardware/spi.h>) || __has_include(<gmock/gmock.h>)
#include <hardware/spi.h>
#endif // __has_include(<hardware/spi.h>) || __has_include(<gmock/gmock.h>)

1 change: 1 addition & 0 deletions src/sdk/scripts/api_dirs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ hardware rcp
hardware resets
hardware rtc
hardware sha256
hardware spi
4 changes: 4 additions & 0 deletions src/sdk/scripts/blocks/pico_api_alternate_defs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ enum pwm_clkdiv_mode { q, r };
/// @brief Alternate definition for Google Test build.
enum sha256_endianness { s, t };

//// @brief Alternate definition for Google Test build.
typedef int spi_inst_t;
//// @brief Alternate definition for Google Test build.
typedef int spi_hw_t;
//// @brief Alternate definition for Google Test build.
typedef int sha256_result_t;
//// @brief Alternate definition for Google Test build.
Expand Down
14 changes: 7 additions & 7 deletions src/sdk/scripts/generate_body.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ awk '{$1="";$2="";$3="";$4="";print $0}'|\
sed -e 's/__attribute__.*always_inline..//'|sed -e 's/__attribute__.*noreturn..//'|sed -e 's/__rcpinline//' |sed -e 's/static//' | sed -e 's/inline//' | sed -e 's/extern//' | sed -e 's/__force_//' | \
sed -e 's/(/ ( /' | sed -e 's/)$/ )/' | \
sed -e 's/enum /enum_/g' | \
sed -e 's/const /const_/g' | \
sed -e 's/const /const___/g' | \
sed -e 's/void /void_/g' | sed -e 's/^ *void_/void /'| \
sed -e 's/volatile /volatile_/g' | \
sed -e 's/ *\*/\* /g' | \
Expand All @@ -67,7 +67,7 @@ tr -s "[:space:]" | uniq \
# for debug out.
cat "$TEMPLIST" >> debug.hpp

# Gnerate include headers.
# Generate include headers.
echo "#if __has_include(<${MODULE_PREFIX}/${MODULE_NAME}.h>) || __has_include(<gmock/gmock.h>)" >> output/pico_sdk_headers.h
echo "#include <${MODULE_PREFIX}/${MODULE_NAME}.h>" >> output/pico_sdk_headers.h
echo "#endif // __has_include(<${MODULE_PREFIX}/${MODULE_NAME}.h>) || __has_include(<gmock/gmock.h>)" >> output/pico_sdk_headers.h
Expand All @@ -76,24 +76,24 @@ echo "" >> output/pico_sdk_headers.h
# Generate the class delcaration.
# add "virtual" and ";" to be a right function prototype.
echo "#if __has_include(<${MODULE_PREFIX}/${MODULE_NAME}.h>) || __has_include(<gmock/gmock.h>)" >> output/sdkwrapper.hpp
sed -e 's/^/virtual /' < "$TEMPLIST" | sed -e 's/$/;/' | sed -e 's/enum_/enum /g' | sed -e 's/const_/const /g' | sed -e 's/void_/void /g' | sed -e 's/volatile_/volatile /g' >> output/sdkwrapper.hpp
sed -e 's/^/virtual /' < "$TEMPLIST" | sed -e 's/$/;/' | sed -e 's/enum_/enum /g' | sed -e 's/const___/const /g' | sed -e 's/void_/void /g' | sed -e 's/volatile_/volatile /g' >> output/sdkwrapper.hpp
echo "#endif // __has_include(<${MODULE_PREFIX}/${MODULE_NAME}.h>) || __has_include(<gmock/gmock.h>)" >> output/sdkwrapper.hpp
echo "" >> output/sdkwrapper.hpp

# Generate the class implementation
echo "#if __has_include(<${MODULE_PREFIX}/${MODULE_NAME}.h>) || __has_include(<gmock/gmock.h>)" >> output/sdkwrapper.cpp
awk -f awk/gen_impl.awk < "$TEMPLIST" | sed -e 's/enum_/enum /g' | sed -e 's/const_/const /g' | sed -e 's/void_/void /g' | sed -e 's/volatile_/volatile /g' >> output/sdkwrapper.cpp
awk -f awk/gen_impl.awk < "$TEMPLIST" | sed -e 's/enum_/enum /g' | sed -e 's/const___/const /g' | sed -e 's/void_/void /g' | sed -e 's/volatile_/volatile /g' >> output/sdkwrapper.cpp
echo "#endif // __has_include(<${MODULE_PREFIX}/${MODULE_NAME}.h>) || __has_include(<gmock/gmock.h>)" >> output/sdkwrapper.cpp
echo "" >> output/sdkwrapper.cpp

# Generate the API stub
awk -v module="$MODULE" -f awk/gen_apistub.awk < "$TEMPLIST" | sed -e 's/enum_/enum /g' | sed -e 's/const_/const /g' | sed -e 's/void_/void /g' | sed -e 's/volatile_/volatile /g' >> output/pico_sdk_apistub.cpp
awk -v module="$MODULE" -f awk/gen_apistub.awk < "$TEMPLIST" | sed -e 's/enum_/enum /g' | sed -e 's/const___/const /g' | sed -e 's/void_/void /g' | sed -e 's/volatile_/volatile /g' >> output/pico_sdk_apistub.cpp

# Generate the mock declaration
sed -e 's/volatile_//g' < "$TEMPLIST" | awk -f awk/gen_mock.awk - | sed -e 's/enum_/enum /g' | sed -e 's/const_/const /g' | sed -e 's/void_/void /g' >> output/mocksdkwrapper.hpp
sed -e 's/volatile_//g' < "$TEMPLIST" | awk -f awk/gen_mock.awk - | sed -e 's/enum_/enum /g' | sed -e 's/const___/const /g' | sed -e 's/void_/void /g' >> output/mocksdkwrapper.hpp

# Generate the fff declaration
# awk -f awk/gen_fff.awk < "$TEMPLIST" | sed -e 's/enum_/enum /g' | sed -e 's/const_/const /g' | sed -e 's/void_/void /g' | sed -e 's/volatile_/volatile /g' >> output/fffsdkwrapper.hpp
# awk -f awk/gen_fff.awk < "$TEMPLIST" | sed -e 's/enum_/enum /g' | sed -e 's/const___/const /g' | sed -e 's/void_/void /g' | sed -e 's/volatile_/volatile /g' >> output/fffsdkwrapper.hpp

# Remove the scratch pad files.
trap 'rm -f "$TEMPSRC"' EXIT
Expand Down
110 changes: 110 additions & 0 deletions src/sdk/sdkwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3386,3 +3386,113 @@ void rpp_driver::SdkWrapper::sha256_wait_valid_blocking(void) {
::sha256_wait_valid_blocking();
}
#endif // __has_include(<hardware/sha256.h>) || __has_include(<gmock/gmock.h>)

#if __has_include(<hardware/spi.h>) || __has_include(<gmock/gmock.h>)
// --------------------------------------------------
extern "C" void spi_deinit(spi_inst_t* spi);
void rpp_driver::SdkWrapper::spi_deinit(spi_inst_t* spi) { ::spi_deinit(spi); }
// --------------------------------------------------
extern "C" uint spi_get_baudrate(const spi_inst_t* spi);
uint rpp_driver::SdkWrapper::spi_get_baudrate(const spi_inst_t* spi) {
return ::spi_get_baudrate(spi);
}
// --------------------------------------------------
extern "C" const spi_hw_t* spi_get_const_hw(const spi_inst_t* spi);
const spi_hw_t* rpp_driver::SdkWrapper::spi_get_const_hw(
const spi_inst_t* spi) {
return ::spi_get_const_hw(spi);
}
// --------------------------------------------------
extern "C" uint spi_get_dreq(spi_inst_t* spi, bool is_tx);
uint rpp_driver::SdkWrapper::spi_get_dreq(spi_inst_t* spi, bool is_tx) {
return ::spi_get_dreq(spi, is_tx);
}
// --------------------------------------------------
extern "C" spi_hw_t* spi_get_hw(spi_inst_t* spi);
spi_hw_t* rpp_driver::SdkWrapper::spi_get_hw(spi_inst_t* spi) {
return ::spi_get_hw(spi);
}
// --------------------------------------------------
extern "C" uint spi_get_index(const spi_inst_t* spi);
uint rpp_driver::SdkWrapper::spi_get_index(const spi_inst_t* spi) {
return ::spi_get_index(spi);
}
// --------------------------------------------------
extern "C" uint spi_init(spi_inst_t* spi, uint baudrate);
uint rpp_driver::SdkWrapper::spi_init(spi_inst_t* spi, uint baudrate) {
return ::spi_init(spi, baudrate);
}
// --------------------------------------------------
extern "C" bool spi_is_busy(const spi_inst_t* spi);
bool rpp_driver::SdkWrapper::spi_is_busy(const spi_inst_t* spi) {
return ::spi_is_busy(spi);
}
// --------------------------------------------------
extern "C" bool spi_is_readable(const spi_inst_t* spi);
bool rpp_driver::SdkWrapper::spi_is_readable(const spi_inst_t* spi) {
return ::spi_is_readable(spi);
}
// --------------------------------------------------
extern "C" bool spi_is_writable(const spi_inst_t* spi);
bool rpp_driver::SdkWrapper::spi_is_writable(const spi_inst_t* spi) {
return ::spi_is_writable(spi);
}
// --------------------------------------------------
extern "C" int spi_read16_blocking(spi_inst_t* spi, uint16_t repeated_tx_data,
uint16_t* dst, size_t len);
int rpp_driver::SdkWrapper::spi_read16_blocking(spi_inst_t* spi,
uint16_t repeated_tx_data,
uint16_t* dst, size_t len) {
return ::spi_read16_blocking(spi, repeated_tx_data, dst, len);
}
// --------------------------------------------------
extern "C" int spi_read_blocking(spi_inst_t* spi, uint8_t repeated_tx_data,
uint8_t* dst, size_t len);
int rpp_driver::SdkWrapper::spi_read_blocking(spi_inst_t* spi,
uint8_t repeated_tx_data,
uint8_t* dst, size_t len) {
return ::spi_read_blocking(spi, repeated_tx_data, dst, len);
}
// --------------------------------------------------
extern "C" uint spi_set_baudrate(spi_inst_t* spi, uint baudrate);
uint rpp_driver::SdkWrapper::spi_set_baudrate(spi_inst_t* spi, uint baudrate) {
return ::spi_set_baudrate(spi, baudrate);
}
// --------------------------------------------------
extern "C" void spi_set_slave(spi_inst_t* spi, bool slave);
void rpp_driver::SdkWrapper::spi_set_slave(spi_inst_t* spi, bool slave) {
::spi_set_slave(spi, slave);
}
// --------------------------------------------------
extern "C" int spi_write16_blocking(spi_inst_t* spi, const uint16_t* src,
size_t len);
int rpp_driver::SdkWrapper::spi_write16_blocking(spi_inst_t* spi,
const uint16_t* src,
size_t len) {
return ::spi_write16_blocking(spi, src, len);
}
// --------------------------------------------------
extern "C" int spi_write16_read16_blocking(spi_inst_t* spi, const uint16_t* src,
uint16_t* dst, size_t len);
int rpp_driver::SdkWrapper::spi_write16_read16_blocking(spi_inst_t* spi,
const uint16_t* src,
uint16_t* dst,
size_t len) {
return ::spi_write16_read16_blocking(spi, src, dst, len);
}
// --------------------------------------------------
extern "C" int spi_write_blocking(spi_inst_t* spi, const uint8_t* src,
size_t len);
int rpp_driver::SdkWrapper::spi_write_blocking(spi_inst_t* spi,
const uint8_t* src, size_t len) {
return ::spi_write_blocking(spi, src, len);
}
// --------------------------------------------------
extern "C" int spi_write_read_blocking(spi_inst_t* spi, const uint8_t* src,
uint8_t* dst, size_t len);
int rpp_driver::SdkWrapper::spi_write_read_blocking(spi_inst_t* spi,
const uint8_t* src,
uint8_t* dst, size_t len) {
return ::spi_write_read_blocking(spi, src, dst, len);
}
#endif // __has_include(<hardware/spi.h>) || __has_include(<gmock/gmock.h>)
27 changes: 27 additions & 0 deletions src/sdk/sdkwrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,33 @@ class SdkWrapper {
virtual void sha256_wait_valid_blocking(void);
#endif // __has_include(<hardware/sha256.h>) || __has_include(<gmock/gmock.h>)

#if __has_include(<hardware/spi.h>) || __has_include(<gmock/gmock.h>)
virtual void spi_deinit(spi_inst_t* spi);
virtual uint spi_get_baudrate(const spi_inst_t* spi);
virtual const spi_hw_t* spi_get_const_hw(const spi_inst_t* spi);
virtual uint spi_get_dreq(spi_inst_t* spi, bool is_tx);
virtual spi_hw_t* spi_get_hw(spi_inst_t* spi);
virtual uint spi_get_index(const spi_inst_t* spi);
virtual uint spi_init(spi_inst_t* spi, uint baudrate);
virtual bool spi_is_busy(const spi_inst_t* spi);
virtual bool spi_is_readable(const spi_inst_t* spi);
virtual bool spi_is_writable(const spi_inst_t* spi);
virtual int spi_read16_blocking(spi_inst_t* spi, uint16_t repeated_tx_data,
uint16_t* dst, size_t len);
virtual int spi_read_blocking(spi_inst_t* spi, uint8_t repeated_tx_data,
uint8_t* dst, size_t len);
virtual uint spi_set_baudrate(spi_inst_t* spi, uint baudrate);
virtual void spi_set_slave(spi_inst_t* spi, bool slave);
virtual int spi_write16_blocking(spi_inst_t* spi, const uint16_t* src,
size_t len);
virtual int spi_write16_read16_blocking(spi_inst_t* spi, const uint16_t* src,
uint16_t* dst, size_t len);
virtual int spi_write_blocking(spi_inst_t* spi, const uint8_t* src,
size_t len);
virtual int spi_write_read_blocking(spi_inst_t* spi, const uint8_t* src,
uint8_t* dst, size_t len);
#endif // __has_include(<hardware/spi.h>) || __has_include(<gmock/gmock.h>)

}; // class SdkWrapper

#include "mocksdkwrapper.hpp"
Expand Down
Loading

0 comments on commit 181ea7b

Please sign in to comment.