Skip to content

Commit

Permalink
Configure GPIO in Kconfig (#566)
Browse files Browse the repository at this point in the history
* Put all GPIO defines in gpio_bitaxe.h

* Whitespace

* Use Kconfig.projbuild

* Missing Kconfig
  • Loading branch information
mutatrum authored Jan 4, 2025
1 parent f454b0c commit 61042d9
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 178 deletions.
9 changes: 6 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"idf.portWin": "COM72",
"idf.adapterTargetName": "esp32s3",
"idf.openOcdConfigs": [
"interface/ftdi/esp32_devkitj_v1.cfg",
"target/esp32s3.cfg"
"board/esp32s3-builtin.cfg"
],
"files.associations": {
"freertos.h": "c",
Expand Down Expand Up @@ -52,7 +51,11 @@
"tuple": "c",
"type_traits": "c",
"utility": "c",
"compare": "c"
"compare": "c",
"cmath": "c",
"utils.h": "c",
"task.h": "c",
"stdlib.h": "c"
},
"editor.formatOnSave": false,
"cSpell.words": [
Expand Down
10 changes: 5 additions & 5 deletions components/asic/bm1366.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <stdlib.h>
#include <string.h>

#define BM1366_RST_PIN GPIO_NUM_1
#define GPIO_ASIC_RESET CONFIG_GPIO_ASIC_RESET

#define TYPE_JOB 0x20
#define TYPE_CMD 0x40
Expand Down Expand Up @@ -318,13 +318,13 @@ static uint8_t _send_init(uint64_t frequency, uint16_t asic_count)
// reset the BM1366 via the RTS line
static void _reset(void)
{
gpio_set_level(BM1366_RST_PIN, 0);
gpio_set_level(GPIO_ASIC_RESET, 0);

// delay for 100ms
vTaskDelay(100 / portTICK_PERIOD_MS);

// set the gpio pin high
gpio_set_level(BM1366_RST_PIN, 1);
gpio_set_level(GPIO_ASIC_RESET, 1);

// delay for 100ms
vTaskDelay(100 / portTICK_PERIOD_MS);
Expand All @@ -344,8 +344,8 @@ uint8_t BM1366_init(uint64_t frequency, uint16_t asic_count)

memset(asic_response_buffer, 0, SERIAL_BUF_SIZE);

esp_rom_gpio_pad_select_gpio(BM1366_RST_PIN);
gpio_set_direction(BM1366_RST_PIN, GPIO_MODE_OUTPUT);
esp_rom_gpio_pad_select_gpio(GPIO_ASIC_RESET);
gpio_set_direction(GPIO_ASIC_RESET, GPIO_MODE_OUTPUT);

// reset the bm1366
_reset();
Expand Down
11 changes: 6 additions & 5 deletions components/asic/bm1368.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "bm1368.h"

#include "crc.h"
#include "global_state.h"
#include "serial.h"
Expand All @@ -14,7 +15,7 @@
#include <stdlib.h>
#include <string.h>

#define BM1368_RST_PIN GPIO_NUM_1
#define GPIO_ASIC_RESET CONFIG_GPIO_ASIC_RESET

#define TYPE_JOB 0x20
#define TYPE_CMD 0x40
Expand Down Expand Up @@ -121,9 +122,9 @@ void BM1368_set_version_mask(uint32_t version_mask)

static void _reset(void)
{
gpio_set_level(BM1368_RST_PIN, 0);
gpio_set_level(GPIO_ASIC_RESET, 0);
vTaskDelay(100 / portTICK_PERIOD_MS);
gpio_set_level(BM1368_RST_PIN, 1);
gpio_set_level(GPIO_ASIC_RESET, 1);
vTaskDelay(100 / portTICK_PERIOD_MS);
}

Expand Down Expand Up @@ -242,8 +243,8 @@ uint8_t BM1368_init(uint64_t frequency, uint16_t asic_count)

memset(asic_response_buffer, 0, CHUNK_SIZE);

esp_rom_gpio_pad_select_gpio(BM1368_RST_PIN);
gpio_set_direction(BM1368_RST_PIN, GPIO_MODE_OUTPUT);
esp_rom_gpio_pad_select_gpio(GPIO_ASIC_RESET);
gpio_set_direction(GPIO_ASIC_RESET, GPIO_MODE_OUTPUT);

_reset();

Expand Down
10 changes: 5 additions & 5 deletions components/asic/bm1370.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <stdlib.h>
#include <string.h>

#define BM1370_RST_PIN GPIO_NUM_1
#define GPIO_ASIC_RESET CONFIG_GPIO_ASIC_RESET

#define TYPE_JOB 0x20
#define TYPE_CMD 0x40
Expand Down Expand Up @@ -329,13 +329,13 @@ static uint8_t _send_init(uint64_t frequency, uint16_t asic_count)
// reset the BM1370 via the RTS line
static void _reset(void)
{
gpio_set_level(BM1370_RST_PIN, 0);
gpio_set_level(GPIO_ASIC_RESET, 0);

// delay for 100ms
vTaskDelay(100 / portTICK_PERIOD_MS);

// set the gpio pin high
gpio_set_level(BM1370_RST_PIN, 1);
gpio_set_level(GPIO_ASIC_RESET, 1);

// delay for 100ms
vTaskDelay(100 / portTICK_PERIOD_MS);
Expand All @@ -355,8 +355,8 @@ uint8_t BM1370_init(uint64_t frequency, uint16_t asic_count)

memset(asic_response_buffer, 0, SERIAL_BUF_SIZE);

esp_rom_gpio_pad_select_gpio(BM1370_RST_PIN);
gpio_set_direction(BM1370_RST_PIN, GPIO_MODE_OUTPUT);
esp_rom_gpio_pad_select_gpio(GPIO_ASIC_RESET);
gpio_set_direction(GPIO_ASIC_RESET, GPIO_MODE_OUTPUT);

// reset the bm1370
_reset();
Expand Down
10 changes: 5 additions & 5 deletions components/asic/bm1397.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "mining.h"
#include "global_state.h"

#define BM1397_RST_PIN GPIO_NUM_1
#define GPIO_ASIC_RESET CONFIG_GPIO_ASIC_RESET

#define TYPE_JOB 0x20
#define TYPE_CMD 0x40
Expand Down Expand Up @@ -278,13 +278,13 @@ static uint8_t _send_init(uint64_t frequency, uint16_t asic_count)
// reset the BM1397 via the RTS line
static void _reset(void)
{
gpio_set_level(BM1397_RST_PIN, 0);
gpio_set_level(GPIO_ASIC_RESET, 0);

// delay for 100ms
vTaskDelay(100 / portTICK_PERIOD_MS);

// set the gpio pin high
gpio_set_level(BM1397_RST_PIN, 1);
gpio_set_level(GPIO_ASIC_RESET, 1);

// delay for 100ms
vTaskDelay(100 / portTICK_PERIOD_MS);
Expand All @@ -296,8 +296,8 @@ uint8_t BM1397_init(uint64_t frequency, uint16_t asic_count)

memset(asic_response_buffer, 0, SERIAL_BUF_SIZE);

esp_rom_gpio_pad_select_gpio(BM1397_RST_PIN);
gpio_set_direction(BM1397_RST_PIN, GPIO_MODE_OUTPUT);
esp_rom_gpio_pad_select_gpio(GPIO_ASIC_RESET);
gpio_set_direction(GPIO_ASIC_RESET, GPIO_MODE_OUTPUT);

// reset the bm1397
_reset();
Expand Down
1 change: 0 additions & 1 deletion main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ SRCS
"EMC2101.c"
"i2c_bitaxe.c"
"INA260.c"
"led_controller.c"
"main.c"
"nvs_config.c"
"display.c"
Expand Down
41 changes: 41 additions & 0 deletions main/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
menu "Bitaxe Configuration"

menu "GPIO Pin Configuration"

config GPIO_BUTTON_BOOT
int "Boot button GPIO pin"
default 0
help
GPIO pin connected to the LED.

config GPIO_ASIC_RESET
int "ASIC reset GPIO pin"
default 1
help
GPIO pin connected to the Button.

config GPIO_ASIC_ENABLE
int "ASIC enable GPIO pin"
default 10
help
GPIO pin for I2C data line (SDA).

config GPIO_PLUG_SENSE
int "Barrel plug sense GPIO pin"
default 12
help
GPIO pin for I2C clock line (SCL).

config GPIO_I2C_SDA
int "I2C SDA Pin"
default 47
help
GPIO pin for I2C clock line (SCL).

config GPIO_I2C_SCL
int "I2C SCL Pin"
default 48
help
GPIO pin for I2C clock line (SCL).

endmenu

config ASIC_VOLTAGE
int "ASIC Core Voltage (mV)"
range 1000 1800
Expand Down
10 changes: 6 additions & 4 deletions main/i2c_bitaxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
#include "esp_log.h"
#include "i2c_bitaxe.h"

#define I2C_MASTER_SCL_IO 48 /*!< GPIO number used for I2C master clock */
#define I2C_MASTER_SDA_IO 47 /*!< GPIO number used for I2C master data */
#define GPIO_I2C_SDA CONFIG_GPIO_I2C_SDA
#define GPIO_I2C_SCL CONFIG_GPIO_I2C_SCL

#define I2C_MASTER_FREQ_HZ 100000 /*!< I2C master clock frequency */

#define I2C_MASTER_NUM 0 /*!< I2C master i2c port number, the number of i2c peripheral interfaces available will depend on the chip */
#define I2C_MASTER_TIMEOUT_MS 1000
Expand All @@ -21,8 +23,8 @@ esp_err_t i2c_bitaxe_init(void)
i2c_master_bus_config_t i2c_bus_config = {
.clk_source = I2C_CLK_SRC_DEFAULT,
.i2c_port = I2C_MASTER_NUM,
.scl_io_num = I2C_MASTER_SCL_IO,
.sda_io_num = I2C_MASTER_SDA_IO,
.scl_io_num = GPIO_I2C_SCL,
.sda_io_num = GPIO_I2C_SDA,
.glitch_ignore_cnt = 7,
.flags.enable_internal_pullup = true,
};
Expand Down
9 changes: 5 additions & 4 deletions main/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#include "esp_lvgl_port.h"
#include "driver/gpio.h"

#define BUTTON_BOOT_GPIO GPIO_NUM_0
#define GPIO_BUTTON_BOOT CONFIG_GPIO_BUTTON_BOOT

#define ESP_INTR_FLAG_DEFAULT 0
#define LONG_PRESS_DURATION_MS 2000

Expand All @@ -24,7 +25,7 @@ static void button_read(lv_indev_t *indev, lv_indev_data_t *data)

static void IRAM_ATTR button_isr_handler(void *arg)
{
bool pressed = gpio_get_level(BUTTON_BOOT_GPIO) == 0; // LOW when pressed
bool pressed = gpio_get_level(GPIO_BUTTON_BOOT) == 0; // LOW when pressed
button_state = pressed ? LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED;
}

Expand All @@ -46,7 +47,7 @@ esp_err_t input_init(void (*button_short_clicked_cb)(void), void (*button_long_p

// Button handling
gpio_config_t io_conf = {
.pin_bit_mask = (1ULL << BUTTON_BOOT_GPIO),
.pin_bit_mask = (1ULL << GPIO_BUTTON_BOOT),
.mode = GPIO_MODE_INPUT,
.pull_up_en = GPIO_PULLUP_ENABLE,
.intr_type = GPIO_INTR_ANYEDGE
Expand All @@ -55,7 +56,7 @@ esp_err_t input_init(void (*button_short_clicked_cb)(void), void (*button_long_p

// Install ISR service and hook the interrupt handler
ESP_RETURN_ON_ERROR(gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT), TAG, "Error installing ISR service");
ESP_RETURN_ON_ERROR(gpio_isr_handler_add(BUTTON_BOOT_GPIO, button_isr_handler, NULL), TAG, "Error adding ISR handler");
ESP_RETURN_ON_ERROR(gpio_isr_handler_add(GPIO_BUTTON_BOOT, button_isr_handler, NULL), TAG, "Error adding ISR handler");

lv_group_t * group = lv_group_create();
lv_group_set_default(group);
Expand Down
Loading

0 comments on commit 61042d9

Please sign in to comment.