Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

SRCS=vfo.c si570.c sbitx_sound.c fft_filter.c sbitx_gtk.c sbitx_utils.c \
i2c.c si5351v2.c ini.c hamlib.c queue.c modems.c logbook.c \
modem_cw.c settings_ui.c oled.c hist_disp.c ntputil.c \
telnet.c macros.c modem_ft8.c remote.c mongoose.c webserver.c sbitx.c
OBJS=$(patsubst %.c,%.o, $(SRCS))

LIBS=ft8_lib/libft8.a
CFLAGS=-O2 -g `pkg-config --cflags gtk+-3.0`
LDFLAGS= -lwiringPi -lasound -lm -lfftw3 -lfftw3f -pthread -lncurses -lsqlite3 \
`pkg-config --libs gtk+-3.0`

sbitx: $(OBJS)
gcc $(LDFLAGS) -o $@ $^ $(LIBS)

clean:
rm $(OBJS) sbitx
165 changes: 165 additions & 0 deletions i2c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*
* i2cBitBangingBus.cpp
*
* Created on: 06.03.2015
* Author: "Marek Wyborski"
*/

#include <fcntl.h>
#include <stdio.h>
#include <inttypes.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <string.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <assert.h>
#include "i2cbb.h"

static int debug = 0;

static int i2c_fd = -1;
void i2cbb_init(uint8_t pin_number_sda, uint8_t pin_number_scl)
{
}

void ensure_open()
{
if (i2c_fd == -1)
{
i2c_fd = open("/dev/i2c-3", O_RDWR);
if (i2c_fd == -1)
{
fprintf(stderr, "Failed to open I2C 3\n");
abort();
}
}
}

// KERNEL-LIKE I2C METHODS

// This executes the SMBus “write byte” protocol, returning negative errno else zero on success.
int32_t i2cbb_write_byte_data(uint8_t i2c_address, uint8_t command, uint8_t value) {

ensure_open();

uint8_t buf[2];

buf[0] = command;
buf[1] = value;

// Write command and all
struct i2c_msg msg;
msg.addr = i2c_address;
msg.flags = 0;
msg.len = 2;
msg.buf = buf;

struct i2c_rdwr_ioctl_data idata;
idata.msgs = &msg;
idata.nmsgs = 1;

int res = ioctl(i2c_fd, I2C_RDWR, &idata);
if (res < 0) {
fprintf(stderr, "Failed to ioctl I2C_RDWR write byte data %x\n", i2c_address);
return -1;
};
if (debug)
fprintf(stderr, "i2c_write_byte data ioctl() cmd %x res %d\n", command, res);

return 0;
}

int32_t i2cbb_write_i2c_block_data(uint8_t i2c_address, uint8_t command,
uint8_t length, const uint8_t * values)
{
ensure_open();

uint8_t buf[256];

assert(length < 256);
buf[0] = command;
memcpy(&buf[1], values, length);

// Write command and all
struct i2c_msg msg;
msg.addr = i2c_address;
msg.flags = 0;
msg.len = length+1;
msg.buf = buf;

struct i2c_rdwr_ioctl_data idata;
idata.msgs = &msg;
idata.nmsgs = 1;

int res = ioctl(i2c_fd, I2C_RDWR, &idata);
if (res < 0) {
fprintf(stderr, "Failed to ioctl I2C_RDWR write i2c block data %x\n", i2c_address);
return -1;
};
if (debug)
fprintf(stderr, "i2c_write_i2c_block_data ioctl() cmd %x length %d res %d\n", command, length, res);

return 0;
}

// This executes the SMBus “block read” protocol, returning negative errno else the number
// of data bytes in the slave's response.
int32_t i2cbb_read_i2c_block_data(uint8_t i2c_address, uint8_t command, uint8_t length,
uint8_t* values) {
ensure_open();

// Command ignored, it's only about reading length bytes
uint8_t buf[256];

struct i2c_msg msg;
msg.addr = i2c_address;
msg.flags = I2C_M_RD;
msg.len = length;
msg.buf = buf;

struct i2c_rdwr_ioctl_data idata;
idata.msgs = &msg;
idata.nmsgs = 1;

int res = ioctl(i2c_fd, I2C_RDWR, &idata);
if (res < 0) {
fprintf(stderr, "Failed to ioctl I2C_RDWR read i2c block data %x len %x\n", i2c_address, length);
return -1;
};

memcpy(values, &buf[0], length);

if (debug)
fprintf(stderr, "i2c_read_i2c_block_data ioctl() res %d length %d\n", res, length);
return length;
}

int32_t i2cbb_read_rll(uint8_t i2c_address, uint8_t* values) {
ensure_open();

uint8_t buf[256];

struct i2c_msg msg;
msg.addr = i2c_address;
msg.flags = I2C_M_RD;
msg.len = 255;
msg.buf = buf;

struct i2c_rdwr_ioctl_data idata;
idata.msgs = &msg;
idata.nmsgs = 1;

int res = ioctl(i2c_fd, I2C_RDWR, &idata);
if (res < 0) {
fprintf(stderr, "Failed to ioctl I2C_RDWR read rll %x len %x\n", i2c_address, buf[0]);
return -1;
};

int rlength = buf[0];
memcpy(values, &buf[1], rlength);

if (debug)
fprintf(stderr, "i2c_read_rll ioctl() length %d res %d\n", rlength, res);
return rlength;
}
6 changes: 4 additions & 2 deletions modem_cw.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,8 @@ float cw_tx_get_sample(){
}
break;
case CW_DOT:
if ((symbol_now & CW_DASH) && cw_next_symbol == CW_IDLE){
if ((symbol_now & CW_DASH) && cw_next_symbol == CW_IDLE && keydown_count < cw_period) {
printf("-- DASH continue\n");
cw_next_symbol = CW_DASH;
}
if (keydown_count == 0){
Expand All @@ -416,7 +417,8 @@ float cw_tx_get_sample(){
}
break;
case CW_DASH:
if ((symbol_now & CW_DOT) && cw_next_symbol == CW_IDLE){
if ((symbol_now & CW_DOT) && cw_next_symbol == CW_IDLE && keydown_count < cw_period) {
printf("-- DOT continue\n");
cw_next_symbol = CW_DOT;
}
if (keydown_count == 0){
Expand Down
Binary file removed sbitx
Binary file not shown.
12 changes: 10 additions & 2 deletions sbitx.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <signal.h>
#include <pthread.h>
#include <errno.h>
#include <assert.h>
#include "sdr.h"
#include "sdr_ui.h"
#include "sound.h"
Expand Down Expand Up @@ -1019,12 +1020,19 @@ static int hw_settings_handler(void* user, const char* section,
char cmd[1000];
char new_value[200];

if (!strcmp(name, "f_start"))
if (!strcmp(name, "f_start")) {
assert(hw_init_index < sizeof(band_power)/sizeof(band_power[0]));
band_power[hw_init_index].f_start = atoi(value);
if (!strcmp(name, "f_stop"))
}
if (!strcmp(name, "f_stop")) {
assert(hw_init_index < sizeof(band_power)/sizeof(band_power[0]));
band_power[hw_init_index].f_stop = atoi(value);
}
if (!strcmp(name, "scale"))
{
assert(hw_init_index < sizeof(band_power)/sizeof(band_power[0]));
band_power[hw_init_index++].scale = atof(value);
}

if (!strcmp(name, "bfo_freq"))
bfo_freq = atoi(value);
Expand Down
34 changes: 31 additions & 3 deletions sbitx_gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct Queue q_zbitx_console;
/* Front Panel controls */
char pins[15] = {0, 2, 3, 6, 7,
10, 11, 12, 13, 14,
21, 22, 23, 25, 27};
21, /*22, 23,*/ 25, 27};

#define ENC1_A (13)
#define ENC1_B (12)
Expand Down Expand Up @@ -3799,8 +3799,36 @@ void tuning_isr(void){
}

void key_isr(void){
dash_state = digitalRead(DASH);
ptt_state = digitalRead(PTT);
// Debounce
static uint8_t dash_input = 2;
static uint8_t ptt_input = 2;
for(int i=0; i < 8; ++i)
{
// LOW means pressed
if (digitalRead(DASH) == LOW)
dash_input = (dash_input << 1) + 1;
else
dash_input = (dash_input << 1) + 0;

if (dash_input == 0xFF)
dash_state = LOW;
else if (dash_input == 0x00)
dash_state = HIGH;

if (digitalRead(PTT) == LOW)
ptt_input = (ptt_input << 1) + 1;
else
ptt_input = (ptt_input << 1) + 0;

if (ptt_input == 0xFF)
ptt_state = LOW;
else if (ptt_input == 0x00)
ptt_state = HIGH;
}
/*
if (dash_state == LOW) fprintf(stderr, ".");
if (ptt_state == LOW) fprintf(stderr, "-");
*/
}

void query_swr(){
Expand Down