mirror of
https://gitlab.com/hyperglitch/jellyfish.git
synced 2025-12-26 15:16:30 +00:00
127 lines
2.8 KiB
C
127 lines
2.8 KiB
C
/*
|
|
* SPDX-FileCopyrightText: 2025 Igor Brkic <igor@hyperglitch.com>
|
|
*
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*/
|
|
|
|
#include "jellyfish.h"
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "aux_power.h"
|
|
#include "main.h"
|
|
|
|
#include "cmsis_os.h"
|
|
|
|
#include "jf_common.h"
|
|
#include "jf_qspi.h"
|
|
#include "jf_i2c.h"
|
|
#include "jf_measure.h"
|
|
#include "jf_ui.h"
|
|
#include "jf_scpi.h"
|
|
#include "jf_source.h"
|
|
#include "jf_usb.h"
|
|
#include "jf_routing.h"
|
|
|
|
extern I2C_HandleTypeDef hi2c3;
|
|
extern TIM_HandleTypeDef htim6;
|
|
extern UART_HandleTypeDef huart1;
|
|
extern QSPI_HandleTypeDef hqspi;
|
|
|
|
osThreadId_t uiTaskHandle;
|
|
const osThreadAttr_t uiTask_attributes = {
|
|
.name = "UITask",
|
|
.stack_size = 6000,
|
|
.priority = (osPriority_t) osPriorityNormal,
|
|
};
|
|
|
|
|
|
void jellyfish_timer_callback() {
|
|
// TIM6 is triggering this callback
|
|
// Counter period:
|
|
// - 18000 -> 5kHz interrupt
|
|
// - 9000 -> 10kHz interrupt
|
|
//HAL_GPIO_TogglePin(DEBUG_PAD_GPIO_Port, DEBUG_PAD_Pin);
|
|
// fetch ADC data
|
|
jf_measure_fetch_data();
|
|
|
|
}
|
|
|
|
|
|
void jellyfish_initialize() {
|
|
|
|
printf("hello from JellyfishOPP\r\n");
|
|
printf("compiled on %s %s\r\n", __DATE__, __TIME__);
|
|
|
|
uint32_t uid[3];
|
|
jf_dev_get_uid(uid);
|
|
char crev[5];
|
|
jf_get_dev_revision_name(crev);
|
|
printf("Hardware revision: %s\r\n", crev);
|
|
printf("Dev UID: %08lx%08lx%08lx\r\n", uid[0], uid[1], uid[2]);
|
|
|
|
// initialize the display and UI
|
|
ui_init();
|
|
|
|
jf_routing_init(); // enable the diode controllers and set default routing
|
|
|
|
jf_qspi_init(&hqspi); // this will init the queue and start the task
|
|
jf_i2c_init(&hi2c3); // this will init the queue and start the task
|
|
|
|
// start the UI task
|
|
uiTaskHandle = osThreadNew(ui_task, NULL, &uiTask_attributes);
|
|
}
|
|
|
|
|
|
|
|
bool write_uart(const uint8_t *c, int len) {
|
|
HAL_StatusTypeDef s = HAL_UART_Transmit(&huart1, c, len, 100);
|
|
return s==HAL_OK;
|
|
}
|
|
|
|
bool write_cdc(const uint8_t *c, int len) {
|
|
jf_usb_cdc_tx((uint8_t*)c, len);
|
|
return true;
|
|
}
|
|
|
|
|
|
void usb_cdc_rx_data(uint8_t *data, uint32_t len) {
|
|
jf_scpi_input(JF_SCPI_IF_USB, (char*)data, (int)len);
|
|
}
|
|
|
|
|
|
void StartDefaultTask(void *argument){
|
|
(void)argument;
|
|
|
|
jf_usb_init();
|
|
|
|
// callback for CDC received data
|
|
jf_usb_set_cdc_rx_callback(usb_cdc_rx_data);
|
|
|
|
jf_measure_init(); // start fetching the data from FPGA
|
|
|
|
jf_source_enable(true);
|
|
jf_source_set_current_limit(3000, JF_CURRENT_LIMIT_BOTH, false);
|
|
jf_source_set_voltage(100, false);
|
|
jf_routing_output_en(true);
|
|
|
|
jf_measure_set_range(JF_RANGE_AUTO, false);
|
|
|
|
jf_vaux_enable(false);
|
|
jf_vaux_set_voltage(0, false);
|
|
|
|
// initialize AUX POWER
|
|
jf_vaux_init();
|
|
|
|
// initialize SCPI interface over UART
|
|
jf_scpi_init(JF_SCPI_IF_UART, write_uart);
|
|
jf_scpi_init(JF_SCPI_IF_USB, write_cdc);
|
|
|
|
// Infinite loop
|
|
for(;;) {
|
|
osDelay(100);
|
|
}
|
|
} |