mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.0 TinyKT0803
This commit is contained in:
parent
ff35f013ef
commit
7e418fc5d5
28
libraries/TinyKT0803/.arduino-ci.yml
Normal file
28
libraries/TinyKT0803/.arduino-ci.yml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
platforms:
|
||||||
|
rpipico:
|
||||||
|
board: rp2040:rp2040:rpipico
|
||||||
|
package: rp2040:rp2040
|
||||||
|
gcc:
|
||||||
|
features:
|
||||||
|
defines:
|
||||||
|
- ARDUINO_ARCH_RP2040
|
||||||
|
warnings:
|
||||||
|
flags:
|
||||||
|
|
||||||
|
packages:
|
||||||
|
rp2040:rp2040:
|
||||||
|
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
|
||||||
|
|
||||||
|
compile:
|
||||||
|
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||||
|
platforms:
|
||||||
|
# - uno
|
||||||
|
# - due
|
||||||
|
# - zero
|
||||||
|
# - leonardo
|
||||||
|
# - m4
|
||||||
|
# - esp32
|
||||||
|
# - esp8266
|
||||||
|
# - mega2560
|
||||||
|
# - rpipico
|
||||||
|
|
4
libraries/TinyKT0803/.github/FUNDING.yml
vendored
Normal file
4
libraries/TinyKT0803/.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: RobTillaart
|
||||||
|
custom: "https://www.paypal.me/robtillaart"
|
14
libraries/TinyKT0803/.github/workflows/arduino-lint.yml
vendored
Normal file
14
libraries/TinyKT0803/.github/workflows/arduino-lint.yml
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
name: Arduino-lint
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 5
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: arduino/arduino-lint-action@v1
|
||||||
|
with:
|
||||||
|
library-manager: update
|
||||||
|
compliance: strict
|
19
libraries/TinyKT0803/.github/workflows/arduino_test_runner.yml
vendored
Normal file
19
libraries/TinyKT0803/.github/workflows/arduino_test_runner.yml
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
---
|
||||||
|
name: Arduino CI
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
runTest:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 20
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: ruby/setup-ruby@v1
|
||||||
|
with:
|
||||||
|
ruby-version: 2.6
|
||||||
|
- run: |
|
||||||
|
# sudo sysctl vm.mmap_rnd_bits=28
|
||||||
|
gem install arduino_ci
|
||||||
|
arduino_ci.rb
|
19
libraries/TinyKT0803/.github/workflows/jsoncheck.yml
vendored
Normal file
19
libraries/TinyKT0803/.github/workflows/jsoncheck.yml
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
name: JSON check
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- '**.json'
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 5
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: json-syntax-check
|
||||||
|
uses: limitusus/json-syntax-check@v2
|
||||||
|
with:
|
||||||
|
pattern: "\\.json$"
|
||||||
|
|
11
libraries/TinyKT0803/CHANGELOG.md
Normal file
11
libraries/TinyKT0803/CHANGELOG.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Change Log TinyKT0803
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||||
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [0.1.0] - 2024-03-26
|
||||||
|
- initial version based upon KT0803
|
21
libraries/TinyKT0803/LICENSE
Normal file
21
libraries/TinyKT0803/LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2023-2024 Rob Tillaart
|
||||||
|
|
||||||
|
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.
|
225
libraries/TinyKT0803/README.md
Normal file
225
libraries/TinyKT0803/README.md
Normal file
@ -0,0 +1,225 @@
|
|||||||
|
|
||||||
|
[![Arduino CI](https://github.com/RobTillaart/TinyKT0803/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||||
|
[![Arduino-lint](https://github.com/RobTillaart/TinyKT0803/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/TinyKT0803/actions/workflows/arduino-lint.yml)
|
||||||
|
[![JSON check](https://github.com/RobTillaart/TinyKT0803/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/TinyKT0803/actions/workflows/jsoncheck.yml)
|
||||||
|
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/TinyKT0803.svg)](https://github.com/RobTillaart/TinyKT0803/issues)
|
||||||
|
|
||||||
|
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/TinyKT0803/blob/master/LICENSE)
|
||||||
|
[![GitHub release](https://img.shields.io/github/release/RobTillaart/TinyKT0803.svg?maxAge=3600)](https://github.com/RobTillaart/TinyKT0803/releases)
|
||||||
|
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/TinyKT0803.svg)](https://registry.platformio.org/libraries/robtillaart/TinyKT0803)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# TinyKT0803
|
||||||
|
|
||||||
|
Arduino Library for KT0803 and KT0803K FM transmitter. Tiny85 edition.
|
||||||
|
|
||||||
|
|
||||||
|
### Legal point of attention
|
||||||
|
|
||||||
|
In different countries there are different laws with respect to using transmitting devices
|
||||||
|
and their range.
|
||||||
|
Please inform yourself of the local rules and laws if and how you may or may not use a
|
||||||
|
device like the KT0803 in your projects, either hobby, commercial or otherwise.
|
||||||
|
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
This is an **EXPERIMENTAL** port to the Tiny85/45/25 processor of - https://github.com/RobTillaart/KT0803
|
||||||
|
|
||||||
|
The library is verified to work - See issue #2
|
||||||
|
There are two points of attention:
|
||||||
|
|
||||||
|
- ATTiny85 needs a 500 ms delay to initialize I2C to communicate properly (assuming 1 MHz clock)
|
||||||
|
- ATTiny85 needs a decoupling capacitor 100-300 nF between RESET and GND and a 10K resistor between VDC and RESET
|
||||||
|
|
||||||
|
Note: The KT0803 library will be leading in development and this one will follow.
|
||||||
|
The interface section below is identical except for the constructor.
|
||||||
|
|
||||||
|
|
||||||
|
## Interface
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#include "TinyKT0803.h"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Constructor
|
||||||
|
|
||||||
|
- **TinyKT0803()** constructor.
|
||||||
|
- **TinyKT0803K()** constructor.
|
||||||
|
- **bool begin(float freq = 90.0, bool mute = true)** initializes the library.
|
||||||
|
Furthermore it checks if the deviceAddress is available on the I2C bus.
|
||||||
|
Default it sets the frequency to 90 MHz and **mutes the signal**.
|
||||||
|
Returns true if deviceAddress is found on the bus, false otherwise.
|
||||||
|
- **bool isConnected()** test to see if deviceAddress is found on the I2C-bus.
|
||||||
|
|
||||||
|
|
||||||
|
#### Frequency
|
||||||
|
|
||||||
|
- **bool setFrequency(float MHz)** converts the frequency in MHz to
|
||||||
|
call **setChannel(channel)**. The value of channel is rounded off depending
|
||||||
|
on the resolution of the device.
|
||||||
|
Returns false if MHz is out of range or **setChannel()** fails.
|
||||||
|
- **float getFrequency()** returns the current frequency in MHz, can be slightly different
|
||||||
|
from the set value due to rounding math mentioned above.
|
||||||
|
The return value is derived from a call to **getChannel()**
|
||||||
|
- **bool setChannel(uint16_t channel)** writes the channel to broadcast on to the device.
|
||||||
|
This involves two or three writes to different device registers.
|
||||||
|
- **uint16_t getChannel()** reads the selected channel from the device and
|
||||||
|
returns it.
|
||||||
|
|
||||||
|
|
||||||
|
#### PGA
|
||||||
|
|
||||||
|
Read Datasheet.
|
||||||
|
|
||||||
|
The KT0803K has a **PGA_LSB** (2 bits) setting, which allows setting the gain
|
||||||
|
with single (1) dB steps. This is not yet implemented in the library.
|
||||||
|
|
||||||
|
- **bool setPGA(uint8_t pga)** sets gain according to table below.
|
||||||
|
Returns false if pga is out of range (0..7).
|
||||||
|
- **uint8_t getPGA()** returns 0..7, default 0.
|
||||||
|
|
||||||
|
|
||||||
|
| PGA | gain | notes |
|
||||||
|
|:-----:|:-------:|:-------:|
|
||||||
|
| 111 | 12dB |
|
||||||
|
| 110 | 8dB |
|
||||||
|
| 101 | 4dB |
|
||||||
|
| 100 | 0dB |
|
||||||
|
| 000 | 0dB | default
|
||||||
|
| 001 | -4dB |
|
||||||
|
| 010 | -8dB |
|
||||||
|
| 011 | -12dB |
|
||||||
|
|
||||||
|
|
||||||
|
#### RFGain
|
||||||
|
|
||||||
|
Read Datasheet.
|
||||||
|
|
||||||
|
Note: the RFGain value (4 bits) is distributed over three registers.
|
||||||
|
PA_BIAS (register 0x05) is only supported in the KT0803K device.
|
||||||
|
It is not yet supported in the library.
|
||||||
|
|
||||||
|
- **bool setRFGain(uint8_t rfgain)** sets rfgain according to table below.
|
||||||
|
Returns false if rfgain is out of range (0..15).
|
||||||
|
- **uint8_t getRFgain()** returns 0..15, default 15.
|
||||||
|
|
||||||
|
|
||||||
|
| RFGAIN | RFout | PA_BIAS = 1 | notes |
|
||||||
|
|:--------:|:------------:|:------------:|:-------:|
|
||||||
|
| 0000 | 95.5 dBuV | - |
|
||||||
|
| 0001 | 96.5 dBuV | - |
|
||||||
|
| 0010 | 97.5 dBuV | - |
|
||||||
|
| 0011 | 98.2 dBuV | - |
|
||||||
|
| 0100 | 98.9 dBuV | - |
|
||||||
|
| 0101 | 100.0 dBuV | - |
|
||||||
|
| 0110 | 101.5 dBuV | - |
|
||||||
|
| 0111 | 102.8 dBuV | - |
|
||||||
|
| 1000 | 105.1 dBuV | 107.2 dBuV |
|
||||||
|
| 1001 | 105.6 dBuV | 108.0 dBuV |
|
||||||
|
| 1010 | 106.2 dBuV | 108.7 dBuV |
|
||||||
|
| 1011 | 106.5 dBuV | 109.5 dBuV |
|
||||||
|
| 1100 | 107.0 dBuV | 110.3 dBuV |
|
||||||
|
| 1101 | 107.4 dBuV | 111.0 dBuV |
|
||||||
|
| 1110 | 107.7 dBuV | 111.7 dBuV |
|
||||||
|
| 1111 | 108.0 dBuV | 112.5 dBuV | default
|
||||||
|
|
||||||
|
|
||||||
|
#### Region selection
|
||||||
|
|
||||||
|
Read datasheet for details.
|
||||||
|
|
||||||
|
Note that not all frequencies are allowed in all regions / countries!
|
||||||
|
|
||||||
|
The first four are convenience wrappers for **setPHTCNST()**
|
||||||
|
If some region is missing please let me know the details and I can add
|
||||||
|
a wrapper for it.
|
||||||
|
|
||||||
|
- **void setEurope()**
|
||||||
|
- **void setAustralia()**
|
||||||
|
- **void setUSA()**
|
||||||
|
- **void setJapan()**
|
||||||
|
- **bool setPHTCNST(bool on)** See table below.
|
||||||
|
- **bool getPHTCNST()** returns set value.
|
||||||
|
|
||||||
|
| PHTCNST | time | Region |
|
||||||
|
|:---------:|:-------:|:--------:|
|
||||||
|
| 0 | 75 μs | USA, Japan, (default)
|
||||||
|
| 1 | 50 μs | Europe, Australia
|
||||||
|
|
||||||
|
|
||||||
|
#### PilotToneAdjust
|
||||||
|
|
||||||
|
Read datasheet.
|
||||||
|
|
||||||
|
- **bool setPilotToneAdjust(uint8_t mode)** HIGH = 1 LOW = 0
|
||||||
|
- **uint8_t getPilotToneAdjust()**
|
||||||
|
|
||||||
|
|
||||||
|
#### Mute
|
||||||
|
|
||||||
|
Default the device is not muted, but **begin()** will default mute it.
|
||||||
|
See interface section above.
|
||||||
|
|
||||||
|
- **bool setMute(bool mute)** enables or disables the transmitting
|
||||||
|
by muting the signal.
|
||||||
|
- **bool getMute()** returns the current state of muting.
|
||||||
|
|
||||||
|
|
||||||
|
## Preference channels
|
||||||
|
|
||||||
|
The device and library do not implement the persistant store of user
|
||||||
|
selectable preferences (frequencies or channels).
|
||||||
|
This can be implemented by the user in EEPROM or another persistent medium.
|
||||||
|
|
||||||
|
Think of a class that holds an array of channels and optional descriptions.
|
||||||
|
A minimal hardcoded preset sketch is in the examples.
|
||||||
|
|
||||||
|
|
||||||
|
## Derived classes
|
||||||
|
|
||||||
|
A derived class TinyKT0803K class is created, with some extended
|
||||||
|
functions.
|
||||||
|
|
||||||
|
The KT0803L will work as it is backwards compatible with KT0803K.
|
||||||
|
It has far more registers in use than the KT0803/K.
|
||||||
|
|
||||||
|
The KT0803M is identical to the KT0803K (no new registers), so
|
||||||
|
a derived class is straightforward.
|
||||||
|
|
||||||
|
|
||||||
|
## Interface KT0803K
|
||||||
|
|
||||||
|
(not tested), check datasheet.
|
||||||
|
|
||||||
|
#### Mono Stereo
|
||||||
|
|
||||||
|
- **bool setMono()** idem
|
||||||
|
- **bool setStereo()** idem
|
||||||
|
- **bool isStereo()** idem
|
||||||
|
|
||||||
|
#### Bass
|
||||||
|
|
||||||
|
- **bool setBass(uint8_t bass); // 0..3 = 0, 5, 11, 17 dB
|
||||||
|
- **uint8_t getBass()** idem
|
||||||
|
|
||||||
|
#### Misc
|
||||||
|
|
||||||
|
- **bool powerOK()** idem
|
||||||
|
- **bool silenceDetected()** idem
|
||||||
|
|
||||||
|
|
||||||
|
## Future
|
||||||
|
|
||||||
|
See - https://github.com/RobTillaart/KT0803
|
||||||
|
|
||||||
|
|
||||||
|
## Support
|
||||||
|
|
||||||
|
If you appreciate my libraries, you can support the development and maintenance.
|
||||||
|
Improve the quality of the libraries by providing issues and Pull Requests, or
|
||||||
|
donate through PayPal or GitHub sponsors.
|
||||||
|
|
||||||
|
Thank you,
|
||||||
|
|
@ -0,0 +1,34 @@
|
|||||||
|
//
|
||||||
|
// FILE: KT0803_minimal.ino
|
||||||
|
// AUTHOR: Rob Tillaart
|
||||||
|
// PURPOSE: minimal demo
|
||||||
|
// URL: https://github.com/RobTillaart/TinyKT0803
|
||||||
|
|
||||||
|
|
||||||
|
#include "TinyKT0803.h"
|
||||||
|
|
||||||
|
|
||||||
|
TinyKT0803 FM_SEND;
|
||||||
|
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
// Tiny only supports SWSerial
|
||||||
|
// Serial.begin(115200);
|
||||||
|
// while(!Serial);
|
||||||
|
|
||||||
|
TinyWireM.begin();
|
||||||
|
// give I2C time to initialize
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
FM_SEND.begin();
|
||||||
|
FM_SEND.setChannel(2000); // * 0.05 = 100.00 MHz
|
||||||
|
FM_SEND.setMute(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -- END OF FILE --
|
36
libraries/TinyKT0803/examples/KT0803_oled/KT0803_oled.ino
Normal file
36
libraries/TinyKT0803/examples/KT0803_oled/KT0803_oled.ino
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// https://github.com/RobTillaart/TinyKT0803/
|
||||||
|
|
||||||
|
#include <TinyKT0803.h>
|
||||||
|
#include <Tiny4kOLED.h>
|
||||||
|
|
||||||
|
TinyKT0803 FM_SEND;
|
||||||
|
|
||||||
|
void oledInit() {
|
||||||
|
oled.begin(128, 64, sizeof(tiny4koled_init_128x64br), tiny4koled_init_128x64br);
|
||||||
|
oled.clear();
|
||||||
|
oled.on();
|
||||||
|
}
|
||||||
|
|
||||||
|
void oledFreq() {
|
||||||
|
oled.clear();
|
||||||
|
oled.setFont(FONT8X16P);
|
||||||
|
oled.setCursor(20, 2);
|
||||||
|
oled.print(FM_SEND.getFrequency());
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
TinyWireM.begin();
|
||||||
|
// give I2C time to initialize (hard coded here)
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
FM_SEND.begin();
|
||||||
|
FM_SEND.setFrequency(97.00);
|
||||||
|
FM_SEND.setMute(false);
|
||||||
|
|
||||||
|
oledInit();
|
||||||
|
oledFreq();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
//
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
//
|
||||||
|
// FILE: KT0803_setFrequency.ino
|
||||||
|
// AUTHOR: Rob Tillaart
|
||||||
|
// PURPOSE: minimal demo
|
||||||
|
// URL: https://github.com/RobTillaart/TinyKT0803
|
||||||
|
|
||||||
|
|
||||||
|
#include "TinyKT0803.h"
|
||||||
|
|
||||||
|
|
||||||
|
TinyKT0803 FM_SEND;
|
||||||
|
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
// Tiny only supports SWSerial
|
||||||
|
// Serial.begin(115200);
|
||||||
|
// while(!Serial);
|
||||||
|
|
||||||
|
TinyWireM.begin();
|
||||||
|
// give I2C time to initialize (hard coded here)
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
FM_SEND.begin();
|
||||||
|
FM_SEND.setFrequency(105.75);
|
||||||
|
FM_SEND.setMute(false);
|
||||||
|
|
||||||
|
// Serial.print("Freq: ");
|
||||||
|
// Serial.println(FM_SEND.getFrequency());
|
||||||
|
// Serial.print("Channel: ");
|
||||||
|
// Serial.println(FM_SEND.getChannel());
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -- END OF FILE --
|
53
libraries/TinyKT0803/keywords.txt
Normal file
53
libraries/TinyKT0803/keywords.txt
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
# Syntax Colouring Map For tinyKT0803
|
||||||
|
|
||||||
|
|
||||||
|
# Data types (KEYWORD1)
|
||||||
|
tinyKT0803 KEYWORD1
|
||||||
|
tinyKT0803K KEYWORD1
|
||||||
|
|
||||||
|
|
||||||
|
# Methods and Functions (KEYWORD2)
|
||||||
|
begin KEYWORD2
|
||||||
|
isConnected KEYWORD2
|
||||||
|
|
||||||
|
setFrequency KEYWORD2
|
||||||
|
getFrequency KEYWORD2
|
||||||
|
setChannel KEYWORD2
|
||||||
|
getChannel KEYWORD2
|
||||||
|
|
||||||
|
setPGA KEYWORD2
|
||||||
|
getPGA KEYWORD2
|
||||||
|
|
||||||
|
setRFGain KEYWORD2
|
||||||
|
getRFgain KEYWORD2
|
||||||
|
|
||||||
|
setEurope KEYWORD2
|
||||||
|
setAustralia KEYWORD2
|
||||||
|
setUSA KEYWORD2
|
||||||
|
setJapan KEYWORD2
|
||||||
|
setPHTCNST KEYWORD2
|
||||||
|
getPHTCNST KEYWORD2
|
||||||
|
|
||||||
|
setPilotToneAdjust KEYWORD2
|
||||||
|
getPilotToneAdjust KEYWORD2
|
||||||
|
|
||||||
|
setMute KEYWORD2
|
||||||
|
getMute KEYWORD2
|
||||||
|
|
||||||
|
|
||||||
|
# KT0803K specific
|
||||||
|
setMono KEYWORD2
|
||||||
|
setStereo KEYWORD2
|
||||||
|
isStereo KEYWORD2
|
||||||
|
|
||||||
|
setBass KEYWORD2
|
||||||
|
getBass KEYWORD2
|
||||||
|
|
||||||
|
powerOK KEYWORD2
|
||||||
|
silenceDetected KEYWORD2
|
||||||
|
|
||||||
|
|
||||||
|
# Constants (LITERAL1)
|
||||||
|
TINY_KT0803_LIB_VERSION LITERAL1
|
||||||
|
|
||||||
|
|
23
libraries/TinyKT0803/library.json
Normal file
23
libraries/TinyKT0803/library.json
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"name": "TinyKT0803",
|
||||||
|
"keywords": "FM,Broadcast,KT0803K,KT0803L,KT0803M,ATTiny25,ATTiny45,ATTiny85",
|
||||||
|
"description": "Arduino library for the KT0803 and KT0803K FM transmitter (tiny edition).\n Based upon KT0803.",
|
||||||
|
"authors":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "Rob Tillaart",
|
||||||
|
"email": "Rob.Tillaart@gmail.com",
|
||||||
|
"maintainer": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"repository":
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/RobTillaart/TinyKT0803.git"
|
||||||
|
},
|
||||||
|
"version": "0.1.0",
|
||||||
|
"license": "MIT",
|
||||||
|
"frameworks": "*",
|
||||||
|
"platforms": "*",
|
||||||
|
"headers": "TinyKT0803.h"
|
||||||
|
}
|
11
libraries/TinyKT0803/library.properties
Normal file
11
libraries/TinyKT0803/library.properties
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
name=TinyKT0803
|
||||||
|
version=0.1.0
|
||||||
|
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
|
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
|
sentence=Arduino library for the KT0803 and KT0803K FM transmitter.(tiny edition). Based upon KT0803.
|
||||||
|
paragraph=KT0803K, KT0803L, KT0803M, ATTiny25, ATTiny45, ATTiny85
|
||||||
|
category=Communication
|
||||||
|
url=https://github.com/RobTillaart/TinyKT0803
|
||||||
|
architectures=*
|
||||||
|
includes=TinyKT0803.h
|
||||||
|
depends=
|
335
libraries/TinyKT0803/src/TinyKT0803.cpp
Normal file
335
libraries/TinyKT0803/src/TinyKT0803.cpp
Normal file
@ -0,0 +1,335 @@
|
|||||||
|
//
|
||||||
|
// FILE: TinyKT0803.cpp
|
||||||
|
// AUTHOR: Rob Tillaart
|
||||||
|
// VERSION: 0.1.0
|
||||||
|
// PURPOSE: Arduino Library for KT0803 and KT0803K FM transmitter. Tiny edition.
|
||||||
|
// URL: https://github.com/RobTillaart/TinyKT0803
|
||||||
|
// URL: https://github.com/RobTillaart/KT0803
|
||||||
|
|
||||||
|
|
||||||
|
#include "TinyKT0803.h"
|
||||||
|
|
||||||
|
|
||||||
|
// REGISTERS on page 7 datasheet
|
||||||
|
|
||||||
|
|
||||||
|
TinyKT0803::TinyKT0803()
|
||||||
|
{
|
||||||
|
_address = 0x3E;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool TinyKT0803::begin(float freq, bool mute)
|
||||||
|
{
|
||||||
|
if (! isConnected()) return false;
|
||||||
|
if (! setMute(mute)) return false;
|
||||||
|
return setFrequency(freq);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool TinyKT0803::isConnected()
|
||||||
|
{
|
||||||
|
TinyWireM.beginTransmission(_address);
|
||||||
|
return (TinyWireM.endTransmission() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// FREQUENCY
|
||||||
|
//
|
||||||
|
bool TinyKT0803::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 TinyKT0803::getFrequency()
|
||||||
|
{
|
||||||
|
return getChannel() * 0.05;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// steps of 50 KHz.
|
||||||
|
bool TinyKT0803::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 TinyKT0803::getChannel()
|
||||||
|
{
|
||||||
|
uint16_t channel = readData(0x01) & 0x07;
|
||||||
|
channel <<= 8;
|
||||||
|
channel |= readData(0x00);
|
||||||
|
channel <<= 1;
|
||||||
|
return channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// GAIN
|
||||||
|
//
|
||||||
|
bool TinyKT0803::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 TinyKT0803::getPGA()
|
||||||
|
{
|
||||||
|
return (readData(0x01) >> 3) & 0x07;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool TinyKT0803::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 TinyKT0803::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 TinyKT0803::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 TinyKT0803::getPHTCNST()
|
||||||
|
{
|
||||||
|
return (readData(0x02) & 0x01) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool TinyKT0803::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 TinyKT0803::getPilotToneAdjust()
|
||||||
|
{
|
||||||
|
return (readData(0x02) & 0x04) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// MUTE
|
||||||
|
//
|
||||||
|
bool TinyKT0803::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 TinyKT0803::getMute()
|
||||||
|
{
|
||||||
|
return (readData(0x02) & 0x08) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// PROTECTED
|
||||||
|
//
|
||||||
|
bool TinyKT0803::writeData(uint8_t reg, uint8_t data)
|
||||||
|
{
|
||||||
|
TinyWireM.beginTransmission(_address);
|
||||||
|
TinyWireM.write(reg);
|
||||||
|
TinyWireM.write(data);
|
||||||
|
return (TinyWireM.endTransmission() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int TinyKT0803::readData(uint8_t reg)
|
||||||
|
{
|
||||||
|
TinyWireM.beginTransmission(_address);
|
||||||
|
TinyWireM.write(reg);
|
||||||
|
TinyWireM.endTransmission(false); // explicit no STOP fig 3 page 4
|
||||||
|
|
||||||
|
// Behaviour differs from TwoWire class
|
||||||
|
// returns 0 if OK, not the bytes available.
|
||||||
|
int rv = TinyWireM.requestFrom(_address, (uint8_t) 1);
|
||||||
|
if (rv == 0)
|
||||||
|
{
|
||||||
|
uint8_t data = TinyWireM.read();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// DERIVED CLASSES
|
||||||
|
//
|
||||||
|
TinyKT0803K::TinyKT0803K() : TinyKT0803()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool TinyKT0803K::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 TinyKT0803K::getChannel()
|
||||||
|
{
|
||||||
|
uint16_t channel = readData(0x01) & 0x07;
|
||||||
|
channel <<= 8;
|
||||||
|
channel |= readData(0x00);
|
||||||
|
channel <<= 1;
|
||||||
|
channel |= (readData(0x02) >> 7);
|
||||||
|
return channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// KT0803K SPECIFIC
|
||||||
|
//
|
||||||
|
bool TinyKT0803K::setMono()
|
||||||
|
{
|
||||||
|
uint8_t register4 = readData(0x04);
|
||||||
|
if (register4 & (1 << 6))
|
||||||
|
{
|
||||||
|
register4 &= ~(1 << 6);
|
||||||
|
return writeData(0x04, register4);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool TinyKT0803K::setStereo()
|
||||||
|
{
|
||||||
|
uint8_t register4 = readData(0x04);
|
||||||
|
if ((register4 & (1 << 6)) == 0)
|
||||||
|
{
|
||||||
|
register4 |= (1 << 6);
|
||||||
|
return writeData(0x04, register4);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TinyKT0803K::isStereo()
|
||||||
|
{
|
||||||
|
uint8_t register4 = readData(0x04);
|
||||||
|
return (register4 & (1 << 6));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool TinyKT0803K::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 TinyKT0803K::getBass()
|
||||||
|
{
|
||||||
|
uint8_t register4 = readData(0x04);
|
||||||
|
return register4 & 0x03;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool TinyKT0803K::powerOK()
|
||||||
|
{
|
||||||
|
uint8_t register0F = readData(0x0F);
|
||||||
|
return (register0F & (1 << 4)) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool TinyKT0803K::silenceDetected()
|
||||||
|
{
|
||||||
|
uint8_t register0F = readData(0x0F);
|
||||||
|
return (register0F & (1 << 2)) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -- END OF FILE --
|
||||||
|
|
114
libraries/TinyKT0803/src/TinyKT0803.h
Normal file
114
libraries/TinyKT0803/src/TinyKT0803.h
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
#pragma once
|
||||||
|
//
|
||||||
|
// FILE: TinyKT0803.h
|
||||||
|
// AUTHOR: Rob Tillaart
|
||||||
|
// VERSION: 0.1.0
|
||||||
|
// PURPOSE: Arduino Library for KT0803 and KT0803K FM transmitter. Tiny edition.
|
||||||
|
// URL: https://github.com/RobTillaart/TinyKT0803
|
||||||
|
// URL: https://github.com/RobTillaart/KT0803
|
||||||
|
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "TinyWireM.h"
|
||||||
|
|
||||||
|
#define TINY_KT0803_LIB_VERSION (F("0.1.0"))
|
||||||
|
|
||||||
|
|
||||||
|
class TinyKT0803
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TinyKT0803();
|
||||||
|
|
||||||
|
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.
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// DERIVED CLASSES
|
||||||
|
//
|
||||||
|
class TinyKT0803K : public TinyKT0803
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TinyKT0803K();
|
||||||
|
|
||||||
|
// 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 --
|
||||||
|
|
Loading…
Reference in New Issue
Block a user