Add initial operacake support
This commit is contained in:
@ -240,6 +240,7 @@ extern w25q80bv_driver_t spi_flash;
|
||||
extern sgpio_config_t sgpio_config;
|
||||
extern rf_path_t rf_path;
|
||||
extern jtag_t jtag_cpld;
|
||||
extern i2c_bus_t i2c0;
|
||||
|
||||
void cpu_clock_init(void);
|
||||
void cpu_clock_pll1_low_speed(void);
|
||||
|
99
firmware/common/operacake.c
Normal file
99
firmware/common/operacake.c
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright 2016 Dominic Spill <dominicgs@gmail.com>
|
||||
*
|
||||
* This file is part of HackRF.
|
||||
*
|
||||
* 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 "operacake.h"
|
||||
#include "hackrf_core.h"
|
||||
|
||||
#define OPERACAKE_PIN_OE (1<<7)
|
||||
#define OPERACAKE_PIN_U2CTRL1 (1<<6)
|
||||
#define OPERACAKE_PIN_U2CTRL0 (1<<5)
|
||||
#define OPERACAKE_PIN_U3CTRL1 (1<<4)
|
||||
#define OPERACAKE_PIN_U3CTRL0 (1<<3)
|
||||
#define OPERACAKE_PIN_U1CTRL (1<<2)
|
||||
#define OPERACAKE_PIN_LEDEN2 (1<<1)
|
||||
#define OPERACAKE_PIN_LEDEN (1<<0)
|
||||
|
||||
#define OPERACAKE_PA1 (!OPERACAKE_PIN_U2CTRL0 | !OPERACAKE_PIN_U2CTRL1)
|
||||
#define OPERACAKE_PA2 (OPERACAKE_PIN_U2CTRL0 | !OPERACAKE_PIN_U2CTRL1)
|
||||
#define OPERACAKE_PA3 (!OPERACAKE_PIN_U2CTRL0 | OPERACAKE_PIN_U2CTRL1)
|
||||
#define OPERACAKE_PA4 (OPERACAKE_PIN_U2CTRL0 | OPERACAKE_PIN_U2CTRL1)
|
||||
|
||||
#define OPERACAKE_PB1 (!OPERACAKE_PIN_U3CTRL0 | !OPERACAKE_PIN_U3CTRL1)
|
||||
#define OPERACAKE_PB2 (OPERACAKE_PIN_U3CTRL0 | !OPERACAKE_PIN_U3CTRL1)
|
||||
#define OPERACAKE_PB3 (!OPERACAKE_PIN_U3CTRL0 | OPERACAKE_PIN_U3CTRL1)
|
||||
#define OPERACAKE_PB4 (OPERACAKE_PIN_U3CTRL0 | OPERACAKE_PIN_U3CTRL1)
|
||||
|
||||
#define OPERACAKE_CROSSOVER (!OPERACAKE_PIN_U1CTRL)
|
||||
#define OPERACAKE_EN_LEDS (OPERACAKE_PIN_LEDEN2 | !OPERACAKE_PIN_LEDEN)
|
||||
|
||||
#define OPERACAKE_REG_INPUT 0x00
|
||||
#define OPERACAKE_REG_OUTPUT 0x01
|
||||
#define OPERACAKE_REG_POLARITY 0x02
|
||||
#define OPERACAKE_REG_CONFIG 0x03
|
||||
|
||||
#define OPERACAKE_DEFAULT_OUTPUT (!OPERACAKE_PIN_OE | OPERACAKE_PA1 | OPERACAKE_PB1 | OPERACAKE_EN_LEDS)
|
||||
#define OPERACAKE_DEFAULT_POLARITY (0x00)//(OPERACAKE_PIN_OE | OPERACAKE_PIN_LEDEN)
|
||||
#define OPERACAKE_CONFIG_ALL_OUTPUT (0x00)
|
||||
|
||||
typedef struct {
|
||||
i2c_bus_t* const bus;
|
||||
uint8_t i2c_address;
|
||||
} operacake_driver_t;
|
||||
|
||||
operacake_driver_t operacake_driver = {
|
||||
.bus = &i2c0,
|
||||
.i2c_address = 0x18,
|
||||
};
|
||||
|
||||
uint8_t operacake_read_single(operacake_driver_t* drv, uint8_t reg);
|
||||
void operacake_write(operacake_driver_t* drv, const uint8_t* const data, const size_t data_count);
|
||||
|
||||
|
||||
uint8_t operacake_init(void) {
|
||||
/* TODO: detect Operacake */
|
||||
uint8_t polarity_data[] = {OPERACAKE_REG_POLARITY,
|
||||
OPERACAKE_DEFAULT_POLARITY};
|
||||
operacake_write(&operacake_driver, polarity_data, 2);
|
||||
uint8_t output_data[] = {OPERACAKE_REG_OUTPUT,
|
||||
OPERACAKE_DEFAULT_OUTPUT};
|
||||
operacake_write(&operacake_driver, output_data, 2);
|
||||
const uint8_t config_data[] = {OPERACAKE_REG_CONFIG,
|
||||
OPERACAKE_CONFIG_ALL_OUTPUT};
|
||||
operacake_write(&operacake_driver, config_data, 2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t operacake_set_ports(uint8_t PA, uint8_t PB) {
|
||||
return PA | PB;
|
||||
}
|
||||
|
||||
/* read single register */
|
||||
uint8_t operacake_read_single(operacake_driver_t* drv, uint8_t reg) {
|
||||
const uint8_t data_tx[] = { reg };
|
||||
uint8_t data_rx[] = { 0x00 };
|
||||
i2c_bus_transfer(drv->bus, drv->i2c_address, data_tx, 1, data_rx, 1);
|
||||
return data_rx[0];
|
||||
}
|
||||
|
||||
/* Write to one of the PCA9557 registers */
|
||||
void operacake_write(operacake_driver_t* drv, const uint8_t* const data, const size_t data_count) {
|
||||
i2c_bus_transfer(drv->bus, drv->i2c_address, data, data_count, NULL, 0);
|
||||
}
|
40
firmware/common/operacake.h
Normal file
40
firmware/common/operacake.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2016 Dominic Spill <dominicgs@gmail.com>
|
||||
*
|
||||
* This file is part of HackRF.
|
||||
*
|
||||
* 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 __OPERACAKE_H
|
||||
#define __OPERACAKE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include "i2c_bus.h"
|
||||
|
||||
uint8_t operacake_init(void);
|
||||
uint8_t operacake_set_ports(uint8_t PA, uint8_t PB);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __OPERACAKE_H */
|
@ -42,6 +42,8 @@ set(SRC_M4
|
||||
usb_api_register.c
|
||||
usb_api_spiflash.c
|
||||
usb_api_transceiver.c
|
||||
"${PATH_HACKRF_FIRMWARE_COMMON}/operacake.c"
|
||||
usb_api_operacake.c
|
||||
"${PATH_HACKRF_FIRMWARE_COMMON}/usb_queue.c"
|
||||
"${PATH_HACKRF_FIRMWARE_COMMON}/fault_handler.c"
|
||||
"${PATH_HACKRF_FIRMWARE_COMMON}/cpld_jtag.c"
|
||||
|
@ -40,6 +40,8 @@
|
||||
#include "usb_api_cpld.h"
|
||||
#include "usb_api_register.h"
|
||||
#include "usb_api_spiflash.h"
|
||||
#include "usb_api_operacake.h"
|
||||
#include "operacake.h"
|
||||
|
||||
#include "usb_api_transceiver.h"
|
||||
#include "sgpio_isr.h"
|
||||
@ -140,6 +142,7 @@ static const usb_request_handler_fn vendor_request_handler[] = {
|
||||
#endif
|
||||
usb_vendor_request_set_freq_explicit,
|
||||
usb_vendor_request_read_wcid, // USB_WCID_VENDOR_REQ
|
||||
usb_vendor_request_operacake_set_ports
|
||||
};
|
||||
|
||||
static const uint32_t vendor_request_handler_count =
|
||||
@ -237,6 +240,7 @@ int main(void) {
|
||||
usb_run(&usb_device);
|
||||
|
||||
rf_path_init(&rf_path);
|
||||
operacake_init();
|
||||
|
||||
unsigned int phase = 0;
|
||||
while(true) {
|
||||
|
37
firmware/hackrf_usb/usb_api_operacake.c
Normal file
37
firmware/hackrf_usb/usb_api_operacake.c
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2016 Dominic Spill <dominicgs@gmail.com>
|
||||
*
|
||||
* This file is part of HackRF.
|
||||
*
|
||||
* 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 "usb_api_operacake.h"
|
||||
#include "usb_queue.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <hackrf_core.h>
|
||||
#include <operacake.h>
|
||||
|
||||
usb_request_status_t usb_vendor_request_operacake_set_ports(
|
||||
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
|
||||
{
|
||||
if (stage == USB_TRANSFER_STAGE_SETUP) {
|
||||
/* TODO: implement something */
|
||||
usb_transfer_schedule_ack(endpoint->in);
|
||||
}
|
||||
return USB_REQUEST_STATUS_OK;
|
||||
}
|
31
firmware/hackrf_usb/usb_api_operacake.h
Normal file
31
firmware/hackrf_usb/usb_api_operacake.h
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2016 Dominic Spill <dominicgs@gmail.com>
|
||||
*
|
||||
* This file is part of HackRF.
|
||||
*
|
||||
* 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 __USB_API_OPERACAKE_H__
|
||||
#define __USB_API_OPERACAKE_H__
|
||||
|
||||
#include <usb_type.h>
|
||||
#include <usb_request.h>
|
||||
|
||||
usb_request_status_t usb_vendor_request_operacake_set_ports(
|
||||
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage);
|
||||
|
||||
#endif /* end of include guard: __USB_API_OPERACAKE_H__ */
|
Reference in New Issue
Block a user