feat(max2871.c): Set the default values after reset
This commit is contained in:
@ -160,10 +160,10 @@ extern "C"
|
|||||||
#define SCU_MIXER_RESETX (P5_5) /* GPIO2[14] on P5_5 */
|
#define SCU_MIXER_RESETX (P5_5) /* GPIO2[14] on P5_5 */
|
||||||
#endif
|
#endif
|
||||||
#ifdef RAD10
|
#ifdef RAD10
|
||||||
#define SCU_MIXER_ENX (P5_4) /* GPIO2[13] on P5_4 */
|
#define SCU_VCO_CE (P5_4) /* GPIO2[13] on P5_4 */
|
||||||
#define SCU_MIXER_SCLK (P2_6) /* GPIO5[6] on P2_6 */
|
#define SCU_VCO_SCLK (P2_6) /* GPIO5[6] on P2_6 */
|
||||||
#define SCU_MIXER_SDATA (P6_4) /* GPIO3[3] on P6_4 */
|
#define SCU_VCO_SDATA (P6_4) /* GPIO3[3] on P6_4 */
|
||||||
#define SCU_MIXER_LE (P5_5) /* GPIO2[14] on P5_5 */
|
#define SCU_VCO_LE (P5_5) /* GPIO2[14] on P5_5 */
|
||||||
#define SCU_MIXER_EN (P6_8) /* GPIO5[16] on P6_8 */
|
#define SCU_MIXER_EN (P6_8) /* GPIO5[16] on P6_8 */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -315,14 +315,14 @@ extern "C"
|
|||||||
#define PORT_MIXER_RESETX (GPIO2)
|
#define PORT_MIXER_RESETX (GPIO2)
|
||||||
#endif
|
#endif
|
||||||
#ifdef RAD10
|
#ifdef RAD10
|
||||||
#define PIN_MIXER_ENX (BIT13) /* GPIO2[13] on P5_4 */
|
#define PIN_VCO_CE (BIT13) /* GPIO2[13] on P5_4 */
|
||||||
#define PORT_MIXER_ENX (GPIO2)
|
#define PORT_VCO_CE (GPIO2)
|
||||||
#define PIN_MIXER_SCLK (BIT6) /* GPIO5[6] on P2_6 */
|
#define PIN_VCO_SCLK (BIT6) /* GPIO5[6] on P2_6 */
|
||||||
#define PORT_MIXER_SCLK (GPIO5)
|
#define PORT_VCO_SCLK (GPIO5)
|
||||||
#define PIN_MIXER_SDATA (BIT3) /* GPIO3[3] on P6_4 */
|
#define PIN_VCO_SDATA (BIT3) /* GPIO3[3] on P6_4 */
|
||||||
#define PORT_MIXER_SDATA (GPIO3)
|
#define PORT_VCO_SDATA (GPIO3)
|
||||||
#define PIN_MIXER_LE (BIT14) /* GPIO2[14] on P5_5 */
|
#define PIN_VCO_LE (BIT14) /* GPIO2[14] on P5_5 */
|
||||||
#define PORT_MIXER_LE (GPIO2)
|
#define PORT_VCO_LE (GPIO2)
|
||||||
#define PIN_MIXER_EN (BIT16) /* GPIO5[16] on P6_8 */
|
#define PIN_MIXER_EN (BIT16) /* GPIO5[16] on P6_8 */
|
||||||
#define PORT_MIXER_EN (GPIO5)
|
#define PORT_MIXER_EN (GPIO5)
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,5 +1,25 @@
|
|||||||
#include <stdint.h>
|
#include "mixer.h"
|
||||||
|
//#include "max2871.h"
|
||||||
|
//#include "mac2871_regs.def" // private register def macros
|
||||||
|
|
||||||
|
#if (defined DEBUG)
|
||||||
|
#include <stdio.h>
|
||||||
|
#define LOG printf
|
||||||
|
#else
|
||||||
|
#define LOG(x,...)
|
||||||
|
#include <libopencm3/lpc43xx/ssp.h>
|
||||||
|
#include <libopencm3/lpc43xx/scu.h>
|
||||||
|
#include <libopencm3/lpc43xx/gpio.h>
|
||||||
|
#include "hackrf_core.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static void max2871_spi_write(uint8_t r, uint32_t v);
|
||||||
|
static void delay_ms(int ms);
|
||||||
|
|
||||||
|
static uint32_t registers[6];
|
||||||
/*
|
/*
|
||||||
* - The input is fixed to 50 MHz
|
* - The input is fixed to 50 MHz
|
||||||
* f_REF = 50 MHz
|
* f_REF = 50 MHz
|
||||||
@ -116,10 +136,110 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void mixer_init(void)
|
|
||||||
{}
|
|
||||||
void mixer_setup(void)
|
void mixer_setup(void)
|
||||||
{}
|
{
|
||||||
|
/* Configure GPIO pins. */
|
||||||
|
scu_pinmux(SCU_VCO_CE, SCU_GPIO_FAST);
|
||||||
|
//scu_pinmux(SCU_VCO_SCLK, SCU_GPIO_FAST | SCU_CONF_FUNCTION4);
|
||||||
|
scu_pinmux(SCU_VCO_SCLK, SCU_GPIO_FAST);
|
||||||
|
scu_pinmux(SCU_VCO_SDATA, SCU_GPIO_FAST);
|
||||||
|
scu_pinmux(SCU_VCO_LE, SCU_GPIO_FAST);
|
||||||
|
|
||||||
|
/* Set GPIO pins as outputs. */
|
||||||
|
GPIO_DIR(PORT_VCO_CE) |= PIN_VCO_CE;
|
||||||
|
GPIO_DIR(PORT_VCO_SCLK) |= PIN_VCO_SCLK;
|
||||||
|
GPIO_DIR(PORT_VCO_SDATA) |= PIN_VCO_SDATA;
|
||||||
|
GPIO_DIR(PORT_VCO_LE) |= PIN_VCO_LE;
|
||||||
|
|
||||||
|
/* set to known state */
|
||||||
|
gpio_set(PORT_VCO_CE, PIN_VCO_CE); /* active high */
|
||||||
|
gpio_clear(PORT_VCO_SCLK, PIN_VCO_SCLK);
|
||||||
|
gpio_clear(PORT_VCO_SDATA, PIN_VCO_SDATA);
|
||||||
|
gpio_set(PORT_VCO_LE, PIN_VCO_LE); /* active low */
|
||||||
|
|
||||||
|
registers[0] = 0x007D0000;
|
||||||
|
registers[1] = 0x2000FFF9;
|
||||||
|
registers[2] = 0x00004042;
|
||||||
|
registers[3] = 0x0000000B;
|
||||||
|
registers[4] = 0x6180B23C;
|
||||||
|
registers[5] = 0x00400005;
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for(i = 5; i >= 0; i--) {
|
||||||
|
max2871_spi_write(i, registers[i]);
|
||||||
|
delay_ms(20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void delay_ms(int ms)
|
||||||
|
{
|
||||||
|
uint32_t i;
|
||||||
|
while(ms--) {
|
||||||
|
for (i = 0; i < 20000; i++) {
|
||||||
|
__asm__("nop");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void serial_delay(void)
|
||||||
|
{
|
||||||
|
uint32_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < 2; i++)
|
||||||
|
__asm__("nop");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* SPI register write
|
||||||
|
*
|
||||||
|
* Send 32 bits:
|
||||||
|
* First 29 bits are data
|
||||||
|
* Last 3 bits are register number
|
||||||
|
*/
|
||||||
|
static void max2871_spi_write(uint8_t r, uint32_t v) {
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
LOG("0x%04x -> reg%d\n", v, r);
|
||||||
|
#else
|
||||||
|
|
||||||
|
uint32_t bits = 32;
|
||||||
|
uint32_t msb = 1 << (bits -1);
|
||||||
|
uint32_t data = v | r;
|
||||||
|
|
||||||
|
/* make sure everything is starting in the correct state */
|
||||||
|
gpio_set(PORT_VCO_LE, PIN_VCO_LE);
|
||||||
|
gpio_clear(PORT_VCO_SCLK, PIN_VCO_SCLK);
|
||||||
|
gpio_clear(PORT_VCO_SDATA, PIN_VCO_SDATA);
|
||||||
|
|
||||||
|
/* start transaction by bringing LE low */
|
||||||
|
gpio_clear(PORT_VCO_LE, PIN_VCO_LE);
|
||||||
|
|
||||||
|
while (bits--) {
|
||||||
|
if (data & msb)
|
||||||
|
gpio_set(PORT_VCO_SDATA, PIN_VCO_SDATA);
|
||||||
|
else
|
||||||
|
gpio_clear(PORT_VCO_SDATA, PIN_VCO_SDATA);
|
||||||
|
data <<= 1;
|
||||||
|
|
||||||
|
serial_delay();
|
||||||
|
gpio_set(PORT_VCO_SCLK, PIN_VCO_SCLK);
|
||||||
|
|
||||||
|
serial_delay();
|
||||||
|
gpio_clear(PORT_VCO_SCLK, PIN_VCO_SCLK);
|
||||||
|
}
|
||||||
|
|
||||||
|
gpio_set(PORT_VCO_LE, PIN_VCO_LE);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void max2871_write_registers(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i = 5; i >= 0; i--) {
|
||||||
|
max2871_spi_write(i, registers[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Set frequency (MHz). */
|
/* Set frequency (MHz). */
|
||||||
uint64_t mixer_set_frequency(uint16_t mhz)
|
uint64_t mixer_set_frequency(uint16_t mhz)
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
#ifndef __MIXER_H
|
#ifndef __MIXER_H
|
||||||
#define __MIXER_H
|
#define __MIXER_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
/* Initialize chip. Call _setup() externally, as it calls _init(). */
|
/* Initialize chip. Call _setup() externally, as it calls _init(). */
|
||||||
extern void mixer_init(void);
|
extern void mixer_init(void);
|
||||||
extern void mixer_setup(void);
|
extern void mixer_setup(void);
|
||||||
|
@ -99,9 +99,11 @@ static void switchctrl_set_rad10(uint8_t ctrl) {
|
|||||||
if (ctrl & SWITCHCTRL_MIX_BYPASS) {
|
if (ctrl & SWITCHCTRL_MIX_BYPASS) {
|
||||||
gpio_clear(PORT_BY_MIX, PIN_BY_MIX);
|
gpio_clear(PORT_BY_MIX, PIN_BY_MIX);
|
||||||
gpio_set(PORT_BY_MIX_N, PIN_BY_MIX_N);
|
gpio_set(PORT_BY_MIX_N, PIN_BY_MIX_N);
|
||||||
|
gpio_clear(PORT_MIXER_EN, PIN_MIXER_EN);
|
||||||
} else {
|
} else {
|
||||||
gpio_set(PORT_BY_MIX, PIN_BY_MIX);
|
gpio_set(PORT_BY_MIX, PIN_BY_MIX);
|
||||||
gpio_clear(PORT_BY_MIX_N, PIN_BY_MIX_N);
|
gpio_clear(PORT_BY_MIX_N, PIN_BY_MIX_N);
|
||||||
|
gpio_set(PORT_MIXER_EN, PIN_MIXER_EN);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctrl & SWITCHCTRL_HP) {
|
if (ctrl & SWITCHCTRL_HP) {
|
||||||
@ -301,6 +303,7 @@ void rf_path_pin_setup() {
|
|||||||
scu_pinmux(SCU_LOW_HIGH_FILT_N,SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
|
scu_pinmux(SCU_LOW_HIGH_FILT_N,SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
|
||||||
scu_pinmux(SCU_TX_AMP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
|
scu_pinmux(SCU_TX_AMP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
|
||||||
scu_pinmux(SCU_RX_LNA, SCU_GPIO_FAST | SCU_CONF_FUNCTION4);
|
scu_pinmux(SCU_RX_LNA, SCU_GPIO_FAST | SCU_CONF_FUNCTION4);
|
||||||
|
scu_pinmux(SCU_MIXER_EN, SCU_GPIO_FAST | SCU_CONF_FUNCTION4);
|
||||||
|
|
||||||
/* Configure RF power supply (VAA) switch */
|
/* Configure RF power supply (VAA) switch */
|
||||||
scu_pinmux(SCU_VAA_ENABLE, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
|
scu_pinmux(SCU_VAA_ENABLE, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
|
||||||
@ -310,6 +313,7 @@ void rf_path_pin_setup() {
|
|||||||
GPIO1_DIR |= PIN_BY_AMP | PIN_TX_RX_N | PIN_BY_MIX;
|
GPIO1_DIR |= PIN_BY_AMP | PIN_TX_RX_N | PIN_BY_MIX;
|
||||||
GPIO2_DIR |= PIN_BY_MIX_N | PIN_LOW_HIGH_FILT | PIN_LOW_HIGH_FILT_N | PIN_TX_AMP;
|
GPIO2_DIR |= PIN_BY_MIX_N | PIN_LOW_HIGH_FILT | PIN_LOW_HIGH_FILT_N | PIN_TX_AMP;
|
||||||
GPIO5_DIR |= PIN_BY_AMP_N | PIN_RX_LNA;
|
GPIO5_DIR |= PIN_BY_AMP_N | PIN_RX_LNA;
|
||||||
|
GPIO_DIR(PORT_MIXER_EN) |= PIN_MIXER_EN;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Safe (initial) switch settings turn off both amplifiers and antenna port
|
* Safe (initial) switch settings turn off both amplifiers and antenna port
|
||||||
|
@ -219,7 +219,7 @@ void usb_set_descriptor_by_serial_number(void)
|
|||||||
int main(void) {
|
int main(void) {
|
||||||
pin_setup();
|
pin_setup();
|
||||||
enable_1v8_power();
|
enable_1v8_power();
|
||||||
#ifdef HACKRF_ONE
|
#if (defined HACKRF_ONE || defined RAD10)
|
||||||
enable_rf_power();
|
enable_rf_power();
|
||||||
#endif
|
#endif
|
||||||
cpu_clock_init();
|
cpu_clock_init();
|
||||||
|
Reference in New Issue
Block a user