mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-08-13 11:23:41 +00:00
39424632bb
* Initial commit and pr for HackRF Pro (praline) arch-port to mayhem-firmware. Please see https://github.com/portapack-mayhem/mayhem-firmware/issues/2957. Added flash specifics for -DBOARD=PRALINE. This firmware only builds with toolchain v9.2.1 if hackrf codebase has -B arm in firmware/hackrf_usb/CMakeLists.txt. * Updated CMakeLists.txt per coordination with @HtoToo. For -DBOARD=PRALINE FLASH_MB_SIZE and FLASH_MB_LIMIT_SIZE are now 4. Removed praline specific variable for FLASH limits. * Updated chibios-portapack's board.cpp to support initialization of the HachRF-Pro (praline) FPGA. Added append_fpga_bitstream.py tool to ensure that praline_fgpa.bin bitstream can be appended to -DBOARD=PRALINE produced firmware. In order to ensure successful execution of append_fpga_bitstream.py to append the fpga bitstream we should expect that the bistsream will be located at 0x180000 in flash. This requires that FLASH_MB_LIMIT_SIZE must be 1.5, and FLASH_BYTES_LIMIT_SIZE must be 1535 * 1024. If we want to allow more or less space for the base firmware image sans the fpga bitstream the location of the bistream must be moved to a location other than 0x180000. * Updated location of praline_fpga.bin bitstream to 0x380000 to allow more room for firmware. Firmware now has 3.5MB, or 2MB more available than before as coordinated with @HTotoo. * Expanded #ifndef PRALINE to include og and r9 gpio and pin setup as coordinated with @HTotoo. * Added note for PRALINE FLASH_MB_LIMIT_SIZE and FLASH_BYTES_LIMIT_SIZE to explain why we are using the 3.5 and 3584 values respectively as coordinated with @HTotoo. * Next round of modifications derived heavily, if not entirely from work done by @banandana at https://github.com/Banandana/mayhem-firmware. This commit should power on the HackRF Pro (praline) display, power on the fpga, and enable gpio, and provide debug utilties. There is still a lot of work to be done to fully enable the new praline board with this build and firmware architectural porting effort. However, hackrf-one boards do not seem to be adversely impacted by the #ifdef PRALINE statements, and CMakeLists updates, as far as I have been able to test. * Ran format-code.sh. Updates for this commit are only due to formatting. Tested builds and they seem to work as exptected. * Addressed fixes in firmware/application and firmware/baseband. Stream now flows to capture and looking glass. Issues were related to thread management. Issues were originally addressed by @banandana. * Ran format-code.sh to allow for consistency with autoamted clang checks. * Update hackrf ref repo to mayhem-portapack-hackrf next from https://github.com/portapack-mayhem/hackrf * Addressed format edits necessary to pass clang-format check. * Starting addressing Si5351 Clocks for radio sampling. These updates correctly set the Si5351 clock at start up. There appears to be an issue during runtime when testing with RX Test Init, Capture and Looking glass. * Updated clock_manager.cpp to restore correct function introduced by @banandana when testing with Rx Test Init. * Switched to using decimation for setting the sample rate without changing the Si5351 clock. This assumes that for the praline board Si5351 CLK0 runs at fixed 8 MHz (constant) and the FPGA decimates to get the desired sample rate. For example, for a 1 MHz sample rate -> Si5351 outputs 8 MHz, FPGA decimates by 8. There is still more work needed here, and potential verification that this is the correct way to operate with this new archteitecture. * After deliberating on hackrf_usb hackrf_core.c and radio.c, and reviewing firmware/application/hw/si5351.cpp the original approach of using the aproach detailed in hackrf_core.c sample_rate_frac_set() lines 580-582, via the implementation in firmware/application/hw/si5351.cpp seems like the best place to continue testing efforts. * Tested at ~2.4GHz (2.3 - 2.5) with lookgin glass and was able to receive signals. Added a Signal Path debug app to test gains, and readio mode (receive/transmit). * Added two debug apps for the RFFC507x. Status View and Tuning View. This helped debug some of the potential issues with tuning. * update submodule * format code * Small touch up merging latest next and ensuring build for HackRF One. * Reverted edits to re: firmware/baseband/sd_over_usb/scsi.c and firmware/application/portapack.cpp. Source now builds, had to pull latest hackrf submodule. * Skipped detect hardware for praline board to avoid backscreen in HackRF Pro praline board. --------- Co-authored-by: gullradriel <gullradriel@users.noreply.github.com>
114 lines
5.5 KiB
C++
114 lines
5.5 KiB
C++
/*
|
|
* Copyright (C) 2024 HTotoo.
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
#ifndef __I2CDEVMANAGER_H__
|
|
#define __I2CDEVMANAGER_H__
|
|
|
|
#include <cstdint>
|
|
#include <vector>
|
|
#include <memory>
|
|
#include "ch.h"
|
|
#include "portapack.hpp"
|
|
#include "i2c_pp.hpp"
|
|
#include "i2cdevlist.hpp"
|
|
#include "event_m0.hpp"
|
|
|
|
#define i2cbus portapack::i2c0
|
|
|
|
extern I2C portapack::i2c0;
|
|
|
|
namespace i2cdev {
|
|
|
|
// The device class. You'll derive your from this. Override init() and update();
|
|
class I2cDev {
|
|
public:
|
|
virtual ~I2cDev() {};
|
|
virtual bool init(uint8_t addr) = 0; // returns true if it is that that device we are looking for.
|
|
virtual void update() = 0; // override this, and you'll be able to query your device and broadcast the result to the system
|
|
|
|
void set_update_interval(uint8_t interval); // sets the device's update interval in sec. if you change it, don't forget to change back to it's original value after you finished!
|
|
uint8_t get_update_interval(); // gets the device's update interval in sec
|
|
|
|
bool i2c_read(uint8_t* reg, uint8_t reg_size, uint8_t* data, uint8_t bytes); // if want to read without register addr, just set reg_size to 0. this way can read 8, or 16 or 32 bit registers too. reg_size in bytes! returns true on succes. handles the errcnt automatically!
|
|
bool i2c_write(uint8_t* reg, uint8_t reg_size, uint8_t* data, uint8_t bytes); // if want to write without register addr, just set reg_size to 0. this way can read 8, or 16 or 32 bit registers too. reg_size in bytes! returns true on succes. handles the errcnt automatically!
|
|
|
|
// helpers for easier i2c communication
|
|
uint8_t read8_1(uint8_t reg);
|
|
bool write8_1(uint8_t reg, uint8_t data);
|
|
uint16_t read16_1(uint8_t reg);
|
|
int16_t readS16_1(uint8_t reg);
|
|
uint16_t read16_LE_1(uint8_t reg);
|
|
int16_t readS16_LE_1(uint8_t reg);
|
|
uint32_t read24_1(uint8_t reg);
|
|
|
|
bool lockDevice(); // locks the device's "mutex". returns true on success. guard important communication with this
|
|
void unlockDevice(); // unlocks the device's "mutex"
|
|
inline bool isLocked() { return mtx != 0; }
|
|
|
|
bool need_del = false; // device can self destruct, and re-init when new scan discovers it
|
|
I2C_DEVMDL model = I2CDEVMDL_NOTSET; // overwrite it in the init()!!!
|
|
uint8_t query_interval = 5; // in seconds. can be overriden in init() if necessary
|
|
protected:
|
|
void got_error(); // i2c communication will call this when communication was not ok. you can call it from any part of your code too.
|
|
void got_success(); // i2c communication will call this when the communication was ok. you can call it from any part of your code too.
|
|
|
|
uint8_t addr = 0; // some devices can have different addresses, so we store what was it wound with
|
|
uint8_t errcnt = 0; // error count during communication. if it reaches a threshold set need_del to remove itself from the device list
|
|
uint8_t mtx = 0; // internal lock, so important client code can be skipped when lock is on. check PPMod for an example
|
|
};
|
|
|
|
// store for the devices. may not have a driver if not supported
|
|
class I2DevListElement {
|
|
public:
|
|
uint8_t addr = 0; // i2c addr of the device
|
|
std::unique_ptr<I2cDev> dev = nullptr; // device driver if any
|
|
};
|
|
|
|
class I2CDevManager {
|
|
public:
|
|
static void init(); // creates the thread, and sets an one time full scan
|
|
static void manual_scan(); // it'll init a forced device scan in the thread's next cycle. (1sec max)
|
|
static void set_autoscan_interval(uint16_t interval); // 0 no auto scan, other values: seconds
|
|
static uint16_t get_autoscan_interval();
|
|
static I2cDev* get_dev_by_addr(uint8_t addr); // caller function needs to cast to the specific device!
|
|
static I2cDev* get_dev_by_model(I2C_DEVMDL model); // caller function needs to cast to the specific device!
|
|
static std::vector<I2C_DEVMDL> get_dev_list_by_model(); // returns the currently discovered
|
|
static std::vector<uint8_t> get_gev_list_by_addr(); // returns the currently discovered
|
|
static void setEventDispatcher(EventDispatcher* ed) { _eventDispatcher = ed; }
|
|
static EventDispatcher* get_event_dispatcher() { return _eventDispatcher; }
|
|
|
|
private:
|
|
static uint16_t scan_interval;
|
|
static bool force_scan; // if set to true, on hte next run it'll do an i2c scan, ONCE
|
|
static std::vector<I2DevListElement> devlist;
|
|
|
|
static bool found(uint8_t addr); // returns true on any new device. also initializes the driver if there is a suitable one
|
|
static bool scan(); // return true on any change (delete or found new)
|
|
static void create_thread();
|
|
static msg_t timer_fn(void* arg);
|
|
static Thread* thread;
|
|
static Mutex mutex_list;
|
|
static EventDispatcher* _eventDispatcher;
|
|
};
|
|
}; // namespace i2cdev
|
|
|
|
#endif
|