2015-07-08 11:39:24 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
2024-02-07 03:07:30 -05:00
|
|
|
* Copyleft (ɔ) 2024 zxkmm under GPL license
|
2015-07-08 11:39:24 -04:00
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program 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 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program 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 this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portapack_io.hpp"
|
2024-02-07 03:07:30 -05:00
|
|
|
#include "portapack_persistent_memory.hpp"
|
2015-07-08 11:39:24 -04:00
|
|
|
|
|
|
|
#include "lpc43xx_cpp.hpp"
|
|
|
|
using namespace lpc43xx;
|
|
|
|
|
|
|
|
#include "utility.hpp"
|
|
|
|
|
|
|
|
#include <ch.h>
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
namespace portapack {
|
|
|
|
|
|
|
|
void IO::init() {
|
2023-05-18 16:16:05 -04:00
|
|
|
data_mask_set();
|
|
|
|
data_write_high(0);
|
|
|
|
|
|
|
|
dir_read();
|
|
|
|
lcd_rd_deassert();
|
|
|
|
lcd_wr_deassert();
|
|
|
|
io_stb_deassert();
|
|
|
|
addr(0);
|
|
|
|
|
|
|
|
gpio_dir.output();
|
|
|
|
gpio_lcd_rdx.output();
|
|
|
|
gpio_lcd_wrx.output();
|
|
|
|
gpio_io_stbx.output();
|
|
|
|
gpio_addr.output();
|
|
|
|
gpio_rot_a.input();
|
|
|
|
gpio_rot_b.input();
|
2015-07-08 11:39:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void IO::lcd_backlight(const bool value) {
|
2023-05-18 16:16:05 -04:00
|
|
|
io_reg = (io_reg & 0x7f) | ((value ? 1 : 0) << 7);
|
|
|
|
io_write(1, io_reg);
|
2015-07-08 11:39:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void IO::lcd_reset_state(const bool active) {
|
2023-05-18 16:16:05 -04:00
|
|
|
io_reg = (io_reg & 0xfe) | ((active ? 1 : 0) << 0);
|
|
|
|
io_write(1, io_reg);
|
2015-07-08 11:39:24 -04:00
|
|
|
}
|
|
|
|
|
2017-05-01 05:37:49 -04:00
|
|
|
void IO::audio_reset_state(const bool active) {
|
2023-05-18 16:16:05 -04:00
|
|
|
/* NOTE: This overwrites the contents of the IO register, which for now
|
|
|
|
* have no significance. But someday...?
|
|
|
|
*/
|
|
|
|
io_reg = (io_reg & 0xfd) | ((active ? 1 : 0) << 1);
|
|
|
|
io_write(1, io_reg);
|
2017-05-01 05:37:49 -04:00
|
|
|
}
|
|
|
|
|
Upstream merge to make new revision of PortaPack work (#206)
* Power: Turn off additional peripheral clock branches.
* Update schematic with new symbol table and KiCad standard symbols.
Fix up wires.
* Schematic: Update power net labels.
* Schematic: Update footprint names to match library changes.
* Schematic: Update header vendor and part numbers.
* Schematic: Specify (arbitrary) value for PDN# net.
* Schematic: Remove fourth fiducial. Not standard practice, and was taking up valuable board space.
* Schematic: Add reference oscillator -- options for clipped sine or HCMOS output.
* Schematic: Update copyright year.
* Schematic: Remove CLKOUT to CPLD. It was a half-baked idea.
* Schematic: Add (experimental) GPS circuit.
Add note about charging circuit.
Update date and revision to match PCB.
* PCB: Update from schematic change: now revision 20180819.
Diff was extensive due to net renumbering...
* PCB: Fix GPS courtyard to accommodate crazy solder paste recommendation in integration manual.
PCB: Address DRC clearance violation between via and oscillator pad.
* PCB: Update copyright on drawing.
* Update schematic and PCB date and revision.
* gitignore: Sublime Text editor project/workspace files
* Power: Power up or power down peripheral clock at appropriate times, so firmware doesn't freeze...
* Clocking: Fix incorrect shift for CGU IDIVx_CTRL.PD field.
* LPC43xx: Add CGU IDIVx struct/union type.
* Power: Switch off unused IDIV dividers. Make note of active IDIVs and their use.
* HackRF Mode: Upgrade firmware to 2018.01.1 (API 1.02)
* MAX V CPLD: Refactor class to look more like Xilinx CoolRunner II CPLD class.
* MAX V CPLD: Add BYPASS, SAMPLE support.
Rename enter_isp -> enable, exit_isp -> disable.
Use SAMPLE at start of flash process, which somehow addresses the problem where CFM wouldn't load into SRAM (and become the active bitstream) after flashing.
* MAX V CPLD: Reverse verify data checking logic to make it a little faster.
* CPLD: After reprogramming flash, immediately clamp I/O signals, load to SRAM, and "execute" the new bitstream.
* Si5351: Refactor code, make one of the registers more type-safe.
Clock Manager: Track selected reference clock source for later use in user interface.
* Clock Manager: Add note about PPM only affecting Si5351C PLLA, which always runs from the HackRF 25MHz crystal.
It is assumed an external clock does not need adjustment, though I am open to being convinced otherwise...
* PPM UI: Show "EXT" when showing PPM adjustment and reference clock is external.
* CPLD: Add pins and logic for new PortaPack hardware feature(s).
* CPLD: Bitstream to support new hardware features.
* Clock Generator: Add a couple more setter methods for ClockControl registers.
* Clock Manager: Use shared MCU CLKIN clock control configuration constant.
* Clock Manager: Reduce MCU CLKIN driver current. 2mA should be plenty.
* Clock Manager: Remove redundant clock generator output enable.
* Bootstrap: Remove unnecessary ldscript hack to locate SPIFI mode change code in RAM.
* Bootstrap: Get CPU operating at max frequency as soon as possible.
Update SPIFI speed comment.
Make some more LPC43xx types into unions with uint32_t.
* Bootstrap: Explicitly configure IDIVB for SPIFI, despite LPC43xx bootloader setting it.
* Clock Manager: Init peripherals before CPLD reconfig. Do the clock generator setup after, so we can check presence of PortaPack reference clock with the help of the latest CPLD bitstream.
* Clock Manager: Reverse sense of conditional that determines crystal or non-crystal reference source. This is for an expected upcoming change where multiple external options can be differentiated.
* Bootstrap: Consolidate clock configuration, update SPIFI rate comment.
* Clock Manager: Use IDIVA for clock source for all peripherals, instead of PLL1. Should make switching easier going forward.
Don't use IRC as clock during initial clock manager configuration. Until we switch to GP_CLKIN, we should go flat out...
* ChibiOS M0: Change default clock speed to 204MHz, since bootstrap now maxes out clock speed before starting M0 execution.
* PortaPack IO: Expose method to set reference oscillator enable pin.
* Pin configuration: Do SPIFI pin config with other pins, in preparation for eliminating separate bootloader.
* Pin configuration: Disable input buffers on pins that are never read.
* Revert "ChibiOS M0: Change default clock speed to 204MHz, since bootstrap now maxes out clock speed before starting M0 execution."
This reverts commit c0e2bb6cc4cc656769323bdbb8ee5a16d2d5bb03.
* Remove unused board files.
* Add LPC43xx functions.
* chibios: Replace code with per-peripheral structs defining clocks, interrupts, and reset bits.
* LPC43xx: Add MCPWM peripheral struct.
* clock generator: Use recommended PLL reset register value.
Datasheet recommends a value. AN619 is quiet on the topic, claims the low nibble is default 0b0000.
* GPIO: Tweak masking of SCU function.
I don't remember why I thought this was necessary...
* HAL: Explicitly turn on timer peripheral clocks used as systicks, during init.
* SCU: Add struct to hold pin configuration.
* PAL: Add functions to address The Glitch.
https://greatscottgadgets.com/2018/02-28-we-fixed-the-glitch/
* PAL/board: New IO initialization code
Declare initial state for SCU pin config, GPIOs. Apply initial state during PAL init. Perform VAA slow turn-on to address The Glitch.
* Merge M0 and M4 to eliminate need for bootstrap firmware
During _early_init, detect if we're running on the M4 or M0.
If M4: do M4-specific core initialization, reset peripherals, speed up SPIFI clock, start M0, go to sleep.
If M0: do all the other things.
* Pins: Miscellaneous SCU configuration tweaks.
* Little code clarity improvement.
* bootstrap: Remove, not necessary.
* Clock Manager: Large re-working to support external references.
* Fix merge conflicts
2019-01-11 01:56:21 -05:00
|
|
|
void IO::reference_oscillator(const bool enable) {
|
2023-05-18 16:16:05 -04:00
|
|
|
const uint8_t mask = 1 << 6;
|
|
|
|
io_reg = (io_reg & ~mask) | (enable ? mask : 0);
|
|
|
|
io_write(1, io_reg);
|
Upstream merge to make new revision of PortaPack work (#206)
* Power: Turn off additional peripheral clock branches.
* Update schematic with new symbol table and KiCad standard symbols.
Fix up wires.
* Schematic: Update power net labels.
* Schematic: Update footprint names to match library changes.
* Schematic: Update header vendor and part numbers.
* Schematic: Specify (arbitrary) value for PDN# net.
* Schematic: Remove fourth fiducial. Not standard practice, and was taking up valuable board space.
* Schematic: Add reference oscillator -- options for clipped sine or HCMOS output.
* Schematic: Update copyright year.
* Schematic: Remove CLKOUT to CPLD. It was a half-baked idea.
* Schematic: Add (experimental) GPS circuit.
Add note about charging circuit.
Update date and revision to match PCB.
* PCB: Update from schematic change: now revision 20180819.
Diff was extensive due to net renumbering...
* PCB: Fix GPS courtyard to accommodate crazy solder paste recommendation in integration manual.
PCB: Address DRC clearance violation between via and oscillator pad.
* PCB: Update copyright on drawing.
* Update schematic and PCB date and revision.
* gitignore: Sublime Text editor project/workspace files
* Power: Power up or power down peripheral clock at appropriate times, so firmware doesn't freeze...
* Clocking: Fix incorrect shift for CGU IDIVx_CTRL.PD field.
* LPC43xx: Add CGU IDIVx struct/union type.
* Power: Switch off unused IDIV dividers. Make note of active IDIVs and their use.
* HackRF Mode: Upgrade firmware to 2018.01.1 (API 1.02)
* MAX V CPLD: Refactor class to look more like Xilinx CoolRunner II CPLD class.
* MAX V CPLD: Add BYPASS, SAMPLE support.
Rename enter_isp -> enable, exit_isp -> disable.
Use SAMPLE at start of flash process, which somehow addresses the problem where CFM wouldn't load into SRAM (and become the active bitstream) after flashing.
* MAX V CPLD: Reverse verify data checking logic to make it a little faster.
* CPLD: After reprogramming flash, immediately clamp I/O signals, load to SRAM, and "execute" the new bitstream.
* Si5351: Refactor code, make one of the registers more type-safe.
Clock Manager: Track selected reference clock source for later use in user interface.
* Clock Manager: Add note about PPM only affecting Si5351C PLLA, which always runs from the HackRF 25MHz crystal.
It is assumed an external clock does not need adjustment, though I am open to being convinced otherwise...
* PPM UI: Show "EXT" when showing PPM adjustment and reference clock is external.
* CPLD: Add pins and logic for new PortaPack hardware feature(s).
* CPLD: Bitstream to support new hardware features.
* Clock Generator: Add a couple more setter methods for ClockControl registers.
* Clock Manager: Use shared MCU CLKIN clock control configuration constant.
* Clock Manager: Reduce MCU CLKIN driver current. 2mA should be plenty.
* Clock Manager: Remove redundant clock generator output enable.
* Bootstrap: Remove unnecessary ldscript hack to locate SPIFI mode change code in RAM.
* Bootstrap: Get CPU operating at max frequency as soon as possible.
Update SPIFI speed comment.
Make some more LPC43xx types into unions with uint32_t.
* Bootstrap: Explicitly configure IDIVB for SPIFI, despite LPC43xx bootloader setting it.
* Clock Manager: Init peripherals before CPLD reconfig. Do the clock generator setup after, so we can check presence of PortaPack reference clock with the help of the latest CPLD bitstream.
* Clock Manager: Reverse sense of conditional that determines crystal or non-crystal reference source. This is for an expected upcoming change where multiple external options can be differentiated.
* Bootstrap: Consolidate clock configuration, update SPIFI rate comment.
* Clock Manager: Use IDIVA for clock source for all peripherals, instead of PLL1. Should make switching easier going forward.
Don't use IRC as clock during initial clock manager configuration. Until we switch to GP_CLKIN, we should go flat out...
* ChibiOS M0: Change default clock speed to 204MHz, since bootstrap now maxes out clock speed before starting M0 execution.
* PortaPack IO: Expose method to set reference oscillator enable pin.
* Pin configuration: Do SPIFI pin config with other pins, in preparation for eliminating separate bootloader.
* Pin configuration: Disable input buffers on pins that are never read.
* Revert "ChibiOS M0: Change default clock speed to 204MHz, since bootstrap now maxes out clock speed before starting M0 execution."
This reverts commit c0e2bb6cc4cc656769323bdbb8ee5a16d2d5bb03.
* Remove unused board files.
* Add LPC43xx functions.
* chibios: Replace code with per-peripheral structs defining clocks, interrupts, and reset bits.
* LPC43xx: Add MCPWM peripheral struct.
* clock generator: Use recommended PLL reset register value.
Datasheet recommends a value. AN619 is quiet on the topic, claims the low nibble is default 0b0000.
* GPIO: Tweak masking of SCU function.
I don't remember why I thought this was necessary...
* HAL: Explicitly turn on timer peripheral clocks used as systicks, during init.
* SCU: Add struct to hold pin configuration.
* PAL: Add functions to address The Glitch.
https://greatscottgadgets.com/2018/02-28-we-fixed-the-glitch/
* PAL/board: New IO initialization code
Declare initial state for SCU pin config, GPIOs. Apply initial state during PAL init. Perform VAA slow turn-on to address The Glitch.
* Merge M0 and M4 to eliminate need for bootstrap firmware
During _early_init, detect if we're running on the M4 or M0.
If M4: do M4-specific core initialization, reset peripherals, speed up SPIFI clock, start M0, go to sleep.
If M0: do all the other things.
* Pins: Miscellaneous SCU configuration tweaks.
* Little code clarity improvement.
* bootstrap: Remove, not necessary.
* Clock Manager: Large re-working to support external references.
* Fix merge conflicts
2019-01-11 01:56:21 -05:00
|
|
|
}
|
|
|
|
|
2024-02-07 03:07:30 -05:00
|
|
|
bool IO::get_dark_cover() {
|
2024-09-08 03:35:09 -04:00
|
|
|
return portapack::persistent_memory::apply_fake_brightness() & (!portapack::persistent_memory::config_lcd_inverted_mode());
|
2024-02-07 03:07:30 -05:00
|
|
|
}
|
|
|
|
|
2024-09-07 04:58:57 -04:00
|
|
|
bool IO::get_is_inverted() {
|
|
|
|
return portapack::persistent_memory::config_lcd_inverted_mode();
|
|
|
|
}
|
|
|
|
|
2024-02-07 03:07:30 -05:00
|
|
|
uint8_t IO::get_brightness() {
|
|
|
|
return portapack::persistent_memory::fake_brightness_level();
|
|
|
|
}
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
uint32_t IO::io_update(const TouchPinsConfig write_value) {
|
2023-05-18 16:16:05 -04:00
|
|
|
/* Very touchy code to save context of PortaPack data bus while the
|
|
|
|
* resistive touch pin drive is changed. Order of operations is
|
|
|
|
* important to prevent latching spurious data into the LCD or IO
|
|
|
|
* registers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const auto save_data = data_read();
|
|
|
|
const auto addr = gpio_addr.read();
|
|
|
|
const auto dir = gpio_dir.read();
|
|
|
|
|
|
|
|
io_stb_assert();
|
|
|
|
|
|
|
|
/* Switch to read */
|
|
|
|
dir_read();
|
|
|
|
addr_0();
|
|
|
|
__asm__("nop");
|
|
|
|
__asm__("nop");
|
|
|
|
__asm__("nop");
|
|
|
|
const auto switches_raw = data_read();
|
|
|
|
|
|
|
|
/* Switch to write */
|
|
|
|
data_write_low(toUType(write_value));
|
|
|
|
dir_write();
|
|
|
|
__asm__("nop");
|
|
|
|
__asm__("nop");
|
|
|
|
__asm__("nop");
|
|
|
|
io_stb_deassert();
|
|
|
|
|
|
|
|
data_write_low(save_data);
|
|
|
|
if (dir) { /* 0 (write) -> 1 (read) */
|
|
|
|
dir_read();
|
|
|
|
}
|
|
|
|
gpio_addr.write(addr);
|
|
|
|
|
|
|
|
auto dfu_btn = portapack::io.dfu_read() & 0x01;
|
|
|
|
return (switches_raw & 0x7f) | (dfu_btn << 7);
|
2015-07-08 11:39:24 -04:00
|
|
|
}
|
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
} // namespace portapack
|