- Add rough structure of project and create some emty files

This commit is contained in:
2024-05-27 21:58:18 +02:00
parent e7a5b3aeed
commit 7e41e9be67
10 changed files with 609 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
#include <stdio.h>
#include "pico/stdlib.h"
int main()
{
stdio_init_all();
while (true) {
printf("Hello, world!\n");
sleep_ms(1000);
}
}

76
CMakeLists.txt Normal file
View File

@@ -0,0 +1,76 @@
# == DO NEVER EDIT THE NEXT LINES for Raspberry Pi Pico VS Code Extension to work ==
if(WIN32)
set(USERHOME $ENV{USERPROFILE})
else()
set(USERHOME $ENV{HOME})
endif()
set(PICO_SDK_PATH ${USERHOME}/.pico-sdk/sdk/1.5.1)
set(PICO_TOOLCHAIN_PATH ${USERHOME}/.pico-sdk/toolchain/13_2_Rel1)
if(WIN32)
set(pico-sdk-tools_DIR ${USERHOME}/.pico-sdk/tools/1.5.1)
include(${pico-sdk-tools_DIR}/pico-sdk-tools-config.cmake)
include(${pico-sdk-tools_DIR}/pico-sdk-tools-config-version.cmake)
endif()
# ====================================================================================
# Generated Cmake Pico project file
cmake_minimum_required(VERSION 3.13)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Initialise pico_sdk from installed location
# (note this can come from environment, CMake cache etc)
# == DO NEVER EDIT THE NEXT LINES for Raspberry Pi Pico VS Code Extension to work ==
if(WIN32)
set(USERHOME $ENV{USERPROFILE})
else()
set(USERHOME $ENV{HOME})
endif()
set(PICO_SDK_PATH ${USERHOME}/.pico-sdk/sdk/1.5.1)
set(PICO_TOOLCHAIN_PATH ${USERHOME}/.pico-sdk/toolchain/13_2_Rel1)
if(WIN32)
set(pico-sdk-tools_DIR ${USERHOME}/.pico-sdk/tools/1.5.1)
include(${pico-sdk-tools_DIR}/pico-sdk-tools-config.cmake)
include(${pico-sdk-tools_DIR}/pico-sdk-tools-config-version.cmake)
endif()
# ====================================================================================
set(PICO_BOARD pico CACHE STRING "Board type")
# Pull in Raspberry Pi Pico SDK (must be before project)
include(pico_sdk_import.cmake)
if (PICO_SDK_VERSION_STRING VERSION_LESS "1.4.0")
message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.4.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
endif()
project(Autoradio-Zombie-Adapter C CXX ASM)
# Initialise the Raspberry Pi Pico SDK
pico_sdk_init()
# Add executable. Default name is the project name, version 0.1
add_executable(Autoradio-Zombie-Adapter Autoradio-Zombie-Adapter.c )
pico_set_program_name(Autoradio-Zombie-Adapter "Autoradio-Zombie-Adapter")
pico_set_program_version(Autoradio-Zombie-Adapter "0.1")
# Modify the below lines to enable/disable output over UART/USB
pico_enable_stdio_uart(Autoradio-Zombie-Adapter 0)
pico_enable_stdio_usb(Autoradio-Zombie-Adapter 0)
# Add the standard library to the build
target_link_libraries(Autoradio-Zombie-Adapter
pico_stdlib)
# Add the standard include files to the build
target_include_directories(Autoradio-Zombie-Adapter PRIVATE
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts or any other standard includes, if required
)
pico_add_extra_outputs(Autoradio-Zombie-Adapter)

0
general/BT-Modul.c Normal file
View File

0
general/fm-modulator.c Normal file
View File

0
general/sinegenerator.c Normal file
View File

332
hardware/KT0803.cpp Normal file
View File

@@ -0,0 +1,332 @@
//
// FILE: KT0803.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.3.0
// PURPOSE: Arduino Library for KT0803 and KT0803K FM transmitter.
// URL: https://github.com/RobTillaart/KT0803
#include "inlclude/KT0803.h"
// REGISTERS on page 7 datasheet
KT0803::KT0803(TwoWire * wire)
{
_address = 0x3E;
_wire = wire;
}
bool KT0803::begin(float freq, bool mute)
{
if (! isConnected()) return false;
if (! setMute(mute)) return false;
return setFrequency(freq);
}
bool KT0803::isConnected()
{
_wire->beginTransmission(_address);
return (_wire->endTransmission() == 0);
}
///////////////////////////////////////////////////////////
//
// FREQUENCY
//
bool KT0803::setFrequency(float MHz)
{
if ((MHz < 70) || (MHz > 108)) return false;
// steps 50 KHz although KT0803 will truncate to 100 KHz.
return setChannel(round(MHz * 20));
}
// MHz
float KT0803::getFrequency()
{
return getChannel() * 0.05;
}
// steps of 50 KHz.
bool KT0803::setChannel(uint16_t channel)
{
if ((channel < 1400) || (channel > 2160)) return false;
// need to split over 3 registers
// register 2 part skipped (always 0) for KT0803
uint16_t ch = channel >> 1;
uint8_t register0 = ch & 0xFF; // CHSEL[8:1]
if (writeData(0x00, register0) == false) return false;
ch >>= 8;
uint8_t register1 = readData(0x01);
register1 &= 0xF8; // CHSEL[11:9]
register1 |= (ch & 0x07); // CHSEL[11:9]
return writeData(0x01, register1);
}
uint16_t KT0803::getChannel()
{
uint16_t channel = readData(0x01) & 0x07;
channel <<= 8;
channel |= readData(0x00);
channel <<= 1;
return channel;
}
///////////////////////////////////////////////////////////
//
// GAIN
//
bool KT0803::setPGA(uint8_t pga)
{
if (pga > 7) return false;
uint8_t data = readData(0x01);
data &= 0xC7; // keep other bits
data |= (pga << 3);
return writeData(0x01, data);
}
uint8_t KT0803::getPGA()
{
return (readData(0x01) >> 3) & 0x07;
}
bool KT0803::setRFGain(uint8_t rfgain)
{
if (rfgain > 15) return false;
// bits 0 and 1
uint8_t data = readData(0x01) & 0x3F;
data |= (rfgain & 0x03) << 6;
writeData(0x01, data);
// bit 2
data = readData(0x13) & 0x7F;
data |= (rfgain & 0x04) << 5;
writeData(0x13, data);
// bit 3
data = readData(0x02) & 0xBF;
data |= (rfgain & 0x08) << 3;
writeData(0x02, data);
return true;
}
uint8_t KT0803::getRFgain()
{
uint8_t data = readData(0x01) >> 6; // bit 0, 1
data |= ((readData(0x13) & 0x80) >> 5); // bit 2
data |= ((readData(0x02) & 0x40) >> 3); // bit 3
return data;
}
bool KT0803::setPHTCNST(bool on)
{
uint8_t data = readData(0x02);
// is the bit already OK
if ((on == true) && (data & 0x01) == 0x01) return true;
if ((on == false) && (data & 0x01) == 0x00) return true;
// otherwise flip the bit
data = data ^ 0x01;
return writeData(0x02, data);
}
///////////////////////////////////////////////////////////
//
// MISC
//
bool KT0803::getPHTCNST()
{
return (readData(0x02) & 0x01) > 0;
}
bool KT0803::setPilotToneAdjust(uint8_t mode)
{
if (mode > 1) return false;
uint8_t data = readData(0x02);
// is the bit already OK
if ((mode == 1) && (data & 0x04) == 0x04) return true;
if ((mode == 0) && (data & 0x04) == 0x00) return true;
// otherwise flip the bit
data = data ^ 0x04;
return writeData(0x02, data);
}
uint8_t KT0803::getPilotToneAdjust()
{
return (readData(0x02) & 0x04) > 0;
}
///////////////////////////////////////////////////////////
//
// MUTE
//
bool KT0803::setMute(bool mute)
{
uint8_t data = readData(0x02);
// is the bit already OK
if ((mute == true) && (data & 0x08) == 0x08) return true;
if ((mute == false) && (data & 0x08) == 0x00) return true;
// otherwise flip the bit
data = data ^ 0x08;
return writeData(0x02, data);
}
bool KT0803::getMute()
{
return (readData(0x02) & 0x08) > 0;
}
///////////////////////////////////////////////////////////////////////
//
// PROTECTED
//
bool KT0803::writeData(uint8_t reg, uint8_t data)
{
_wire->beginTransmission(_address);
_wire->write(reg);
_wire->write(data);
return (_wire->endTransmission() == 0);
}
int KT0803::readData(uint8_t reg)
{
_wire->beginTransmission(_address);
_wire->write(reg);
_wire->endTransmission(false); // explicit no STOP fig 3 page 4
if (_wire->requestFrom(_address, (uint8_t) 1) == 1)
{
uint8_t data = _wire->read();
return data;
}
return -1;
}
/////////////////////////////////////////////////////////////////////////////
//
// DERIVED CLASSES
//
KT0803K::KT0803K(TwoWire * wire) : KT0803(wire)
{
}
bool KT0803K::setChannel(uint16_t channel)
{
if ((channel < 1400) || (channel > 2160)) return false;
// need to split over 3 registers
uint16_t ch = channel;
uint8_t register2 = readData(0x02) & 0x7F;
register2 |= (channel & 0x01) << 7; // CHSEL[0]
if (writeData(0x02, register2) == false) return false;
ch >>= 1;
uint8_t register0 = ch & 0xFF; // CHSEL[8:1]
if (writeData(0x00, register0) == false) return false;
ch >>= 8;
uint8_t register1 = readData(0x01);
register1 &= 0xF8; // CHSEL[11:9]
register1 |= (ch & 0x07); // CHSEL[11:9]
return writeData(0x01, register1);
}
uint16_t KT0803K::getChannel()
{
uint16_t channel = readData(0x01) & 0x07;
channel <<= 8;
channel |= readData(0x00);
channel <<= 1;
channel |= (readData(0x02) >> 7);
return channel;
}
///////////////////////////////////////////////////////////
//
// KT0803K SPECIFIC
//
bool KT0803K::setMono()
{
uint8_t register4 = readData(0x04);
if (register4 & (1 << 6))
{
register4 &= ~(1 << 6);
return writeData(0x04, register4);
}
return true;
}
bool KT0803K::setStereo()
{
uint8_t register4 = readData(0x04);
if ((register4 & (1 << 6)) == 0)
{
register4 |= (1 << 6);
return writeData(0x04, register4);
}
return true;
}
bool KT0803K::isStereo()
{
uint8_t register4 = readData(0x04);
return (register4 & (1 << 6));
}
bool KT0803K::setBass(uint8_t bass) // 0..3 = 0, 5, 11, 17 dB
{
if (bass > 3) return false;
uint8_t register4 = readData(0x04);
register4 &= ~0x03; // mask off bits
register4 |= bass;
return writeData(0x04, register4);
}
uint8_t KT0803K::getBass()
{
uint8_t register4 = readData(0x04);
return register4 & 0x03;
}
bool KT0803K::powerOK()
{
uint8_t register0F = readData(0x0F);
return (register0F & (1 << 4)) > 0;
}
bool KT0803K::silenceDetected()
{
uint8_t register0F = readData(0x0F);
return (register0F & (1 << 2)) > 0;
}
// -- END OF FILE --

0
hardware/i2c.c Normal file
View File

115
hardware/include/KT0803.h Normal file
View File

@@ -0,0 +1,115 @@
#pragma once
//
// FILE: KT0803.h
// AUTHOR: Rob Tillaart
// VERSION: 0.3.0
// PURPOSE: Arduino Library for KT0803 and KT0803K FM transmitter
// URL: https://github.com/RobTillaart/KT0803
#include "Arduino.h"
#include "Wire.h"
#define KT0803_LIB_VERSION (F("0.3.0"))
class KT0803
{
public:
KT0803(TwoWire * wire = &Wire);
bool begin(float freq = 90.0, bool mute = true);
bool isConnected();
// FM FREQUENCY (70-108)
// KT0803 truncates to 0.1 MHz
// KT0803K (L&M) truncates to 0.05 MHz
bool setFrequency(float MHz);
float getFrequency();
// FM CHANNEL (1400-2160)
// KT0803 only supports even channels
// KT0803K (L&M) supports all channels
bool setChannel(uint16_t channel);
uint16_t getChannel();
// GAIN
bool setPGA(uint8_t pga); // 0-3 = 0..-12dB 4-7 = 0..12dB
// 111: 12dB
// 110: 8dB
// 101: 4dB
// 100: 0dB
// 000: 0dB
// 001: -4dB
// 010: -8dB
// 011: -12dB
uint8_t getPGA();
bool setRFGain(uint8_t rfgain); // 0-15
uint8_t getRFgain();
// REGION SELECTION
// first four are wrappers
void setEurope() { setPHTCNST(true); };
void setAustralia() { setPHTCNST(true); };
void setUSA() { setPHTCNST(false); };
void setJapan() { setPHTCNST(false); };
bool setPHTCNST(bool on);
bool getPHTCNST();
// PILOT TONE ADJUST (PLTADJ)
bool setPilotToneAdjust(uint8_t mode); // HIGH = 1 LOW = 0
uint8_t getPilotToneAdjust();
// MUTE software
bool setMute(bool mute); // true == muted
bool getMute(); // isMuted().
// direct access to registers - debug / develop
// to access not implemented functions.
bool writeData(uint8_t reg, uint8_t data);
int readData(uint8_t reg);
protected:
uint8_t _address = 0x3E; // fixed address for KT0803.
TwoWire * _wire = NULL;
};
/////////////////////////////////////////////////////////////////////////////
//
// DERIVED CLASSES
//
class KT0803K : public KT0803
{
public:
KT0803K(TwoWire * wire = &Wire);
// CHANNEL
bool setChannel(uint16_t channel);
uint16_t getChannel();
// KT0803K SPECIFIC
bool setMono();
bool setStereo();
bool isStereo();
bool setBass(uint8_t bass); // 0..3 = 0, 5, 11, 17 dB
uint8_t getBass();
bool powerOK();
bool silenceDetected();
};
// -- END OF FILE --

0
hardware/include/i2c.h Normal file
View File

73
pico_sdk_import.cmake Normal file
View File

@@ -0,0 +1,73 @@
# This is a copy of <PICO_SDK_PATH>/external/pico_sdk_import.cmake
# This can be dropped into an external project to help locate this SDK
# It should be include()ed prior to project()
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
endif ()
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')")
endif ()
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
endif ()
set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
if (NOT PICO_SDK_PATH)
if (PICO_SDK_FETCH_FROM_GIT)
include(FetchContent)
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
if (PICO_SDK_FETCH_FROM_GIT_PATH)
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
endif ()
# GIT_SUBMODULES_RECURSE was added in 3.17
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG master
GIT_SUBMODULES_RECURSE FALSE
)
else ()
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG master
)
endif ()
if (NOT pico_sdk)
message("Downloading Raspberry Pi Pico SDK")
FetchContent_Populate(pico_sdk)
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
endif ()
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
else ()
message(FATAL_ERROR
"SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
)
endif ()
endif ()
get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
if (NOT EXISTS ${PICO_SDK_PATH})
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
endif ()
set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
endif ()
set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)
include(${PICO_SDK_INIT_CMAKE_FILE})