mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-24 05:11:24 +01:00
fa00e9e11b
commitf13824164b
Author: Asbelos <asbelos@btinternet.com> Date: Thu Oct 10 16:07:42 2024 +0100 _s7 keyword generator commit8a7dc2643c
Author: Asbelos <asbelos@btinternet.com> Date: Mon Oct 7 10:54:05 2024 +0100 comments commit801cddfef7
Author: Asbelos <asbelos@btinternet.com> Date: Sun Oct 6 13:24:07 2024 +0100 simpler macro insert commit5883f474ee
Author: Asbelos <asbelos@btinternet.com> Date: Sun Oct 6 13:18:29 2024 +0100 Auto include commit312fc255e4
Author: Asbelos <asbelos@btinternet.com> Date: Sun Oct 6 13:12:51 2024 +0100 Cleanup to one class commit3094074349
Author: Asbelos <asbelos@btinternet.com> Date: Sun Oct 6 10:34:16 2024 +0100 peeled back commitaa2a6ad119
Author: Asbelos <asbelos@btinternet.com> Date: Sat Oct 5 18:27:43 2024 +0100 all fastpins commit931baf4b6d
Author: Asbelos <asbelos@btinternet.com> Date: Sat Oct 5 16:28:03 2024 +0100 Partial lib extract commit47bc3b55fc
Author: Asbelos <asbelos@btinternet.com> Date: Fri Oct 4 15:41:51 2024 +0100 fixes and SEG7 macro commit3f26ca2d1a
Author: Asbelos <asbelos@btinternet.com> Date: Fri Oct 4 14:33:23 2024 +0100 enums for exrail easy commit7e7c00594b
Author: Asbelos <asbelos@btinternet.com> Date: Fri Oct 4 13:16:57 2024 +0100 Working commitfc4df87848
Author: Asbelos <asbelos@btinternet.com> Date: Fri Oct 4 09:27:46 2024 +0100 leds and buttons
135 lines
3.6 KiB
C++
135 lines
3.6 KiB
C++
/*
|
|
* © 2024, Chris Harlow. All rights reserved.
|
|
*
|
|
* This file is part of DCC++EX API
|
|
*
|
|
* This is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* It is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef IO_TM1638_h
|
|
#define IO_TM1638_h
|
|
#include <Arduino.h>
|
|
#include "IODevice.h"
|
|
#include "DIAG.h"
|
|
|
|
class TM1638 : public IODevice {
|
|
private:
|
|
|
|
uint8_t _buttons;
|
|
uint8_t _leds;
|
|
unsigned long _lastLoop;
|
|
static const int LoopHz=20;
|
|
|
|
static const byte
|
|
INSTRUCTION_WRITE_DATA=0x40,
|
|
INSTRUCTION_READ_KEY=0x42,
|
|
INSTRUCTION_ADDRESS_AUTO=0x40,
|
|
INSTRUCTION_ADDRESS_FIXED=0x44,
|
|
INSTRUCTION_NORMAL_MODE=0x40,
|
|
INSTRUCTION_TEST_MODE=0x48,
|
|
|
|
FIRST_DISPLAY_ADDRESS=0xC0,
|
|
|
|
DISPLAY_TURN_OFF=0x80,
|
|
DISPLAY_TURN_ON=0x88;
|
|
|
|
|
|
uint8_t _clk_pin;
|
|
uint8_t _stb_pin;
|
|
uint8_t _dio_pin;
|
|
uint8_t _pulse;
|
|
bool _isOn;
|
|
|
|
|
|
// Constructor
|
|
TM1638(VPIN firstVpin, byte clk_pin,byte dio_pin,byte stb_pin);
|
|
|
|
public:
|
|
enum DigitFormat : byte {
|
|
// last 4 bits are length.
|
|
// DF_1.. DF_8 decimal
|
|
DF_1=0x01,DF_2=0x02,DF_3=0x03,DF_4=0x04,
|
|
DF_5=0x05,DF_6=0x06,DF_7=0x07,DF_8=0x08,
|
|
// DF_1X.. DF_8X HEX
|
|
DF_1X=0x11,DF_2X=0x12,DF_3X=0x13,DF_4X=0x14,
|
|
DF_5X=0x15,DF_6X=0x16,DF_7X=0x17,DF_8X=0x18,
|
|
// DF_1R .. DF_4R raw 7 segmnent data
|
|
// only 4 because HAL analogWrite only passes 4 bytes
|
|
DF_1R=0x21,DF_2R=0x22,DF_3R=0x23,DF_4R=0x24,
|
|
|
|
// bits of data conversion type (ored with length)
|
|
_DF_DECIMAL=0x00,// right adjusted decimal unsigned leading zeros
|
|
_DF_HEX=0x10, // right adjusted hex leading zeros
|
|
_DF_RAW=0x20 // bytes are raw 7-segment pattern (max length 4)
|
|
};
|
|
|
|
static void create(VPIN firstVpin, byte clk_pin,byte dio_pin,byte stb_pin);
|
|
|
|
// Functions overridden in IODevice
|
|
void _begin();
|
|
void _loop(unsigned long currentMicros) override ;
|
|
void _writeAnalogue(VPIN vpin, int value, uint8_t param1, uint16_t param2) override;
|
|
void _display() override ;
|
|
int _read(VPIN pin) override;
|
|
void _write(VPIN pin,int value) override;
|
|
|
|
// Device driving functions
|
|
private:
|
|
enum pulse_t {
|
|
PULSE1_16,
|
|
PULSE2_16,
|
|
PULSE4_16,
|
|
PULSE10_16,
|
|
PULSE11_16,
|
|
PULSE12_16,
|
|
PULSE13_16,
|
|
PULSE14_16
|
|
};
|
|
|
|
/**
|
|
* @fn getButtons
|
|
* @return state of 8 buttons
|
|
*/
|
|
uint8_t getButtons();
|
|
|
|
/**
|
|
* @fn writeLed
|
|
* @brief put led ON or OFF
|
|
* @param num num of led(1-8)
|
|
* @param state (true or false)
|
|
*/
|
|
void writeLed(uint8_t num, bool state);
|
|
|
|
|
|
/**
|
|
* @fn displayDig
|
|
* @brief set 7 segment display + dot
|
|
* @param digitId num of digit(0-7)
|
|
* @param val value 8 bits
|
|
*/
|
|
void displayDig(uint8_t digitId, uint8_t pgfedcba);
|
|
|
|
/**
|
|
* @fn displayClear
|
|
* @brief switch off all leds and segment display
|
|
*/
|
|
void displayClear();
|
|
void test();
|
|
void writeData(uint8_t data);
|
|
void writeDataAt(uint8_t displayAddress, uint8_t data);
|
|
void setDisplayMode(uint8_t displayMode);
|
|
void setDataInstruction(uint8_t dataInstruction);
|
|
};
|
|
#endif
|