Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put all GPIO defines in gpio_bitaxe.h #566

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
11 changes: 5 additions & 6 deletions components/asic/bm1366.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "gpio_bitaxe.h"

#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BM1366_RST_PIN GPIO_NUM_1

#define TYPE_JOB 0x20
#define TYPE_CMD 0x40

Expand Down Expand Up @@ -318,13 +317,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 +343,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: 5 additions & 6 deletions components/asic/bm1368.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "gpio_bitaxe.h"

#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BM1368_RST_PIN GPIO_NUM_1

#define TYPE_JOB 0x20
#define TYPE_CMD 0x40

Expand Down Expand Up @@ -121,9 +120,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 +241,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
11 changes: 5 additions & 6 deletions components/asic/bm1370.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "gpio_bitaxe.h"

#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BM1370_RST_PIN GPIO_NUM_1

#define TYPE_JOB 0x20
#define TYPE_CMD 0x40

Expand Down Expand Up @@ -329,13 +328,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 +354,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
11 changes: 5 additions & 6 deletions components/asic/bm1397.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "gpio_bitaxe.h"

#include "serial.h"
#include "bm1397.h"
Expand All @@ -15,8 +16,6 @@
#include "mining.h"
#include "global_state.h"

#define BM1397_RST_PIN GPIO_NUM_1

#define TYPE_JOB 0x20
#define TYPE_CMD 0x40

Expand Down Expand Up @@ -278,13 +277,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 +295,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
11 changes: 11 additions & 0 deletions main/gpio_bitaxe.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef GPIO_BITAXE_H_
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only comment is that it feels backwards that components would depend on a header in the app (main).

#define GPIO_BITAXE_H_

#define GPIO_BUTTON_BOOT GPIO_NUM_0
#define GPIO_ASIC_RESET GPIO_NUM_1
#define GPIO_ASIC_ENABLE GPIO_NUM_10
#define GPIO_PLUG_SENSE GPIO_NUM_12
#define GPIO_I2C_SDA GPIO_NUM_47
#define GPIO_I2C_SCL GPIO_NUM_48

#endif /* GPIO_BITAXE_H_ */
8 changes: 4 additions & 4 deletions main/i2c_bitaxe.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "esp_event.h"
#include "esp_log.h"
#include "i2c_bitaxe.h"
#include "gpio_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 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 +21,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
8 changes: 4 additions & 4 deletions main/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include "lvgl.h"
#include "esp_lvgl_port.h"
#include "driver/gpio.h"
#include "gpio_bitaxe.h"

#define BUTTON_BOOT_GPIO GPIO_NUM_0
#define ESP_INTR_FLAG_DEFAULT 0
#define LONG_PRESS_DURATION_MS 2000

Expand All @@ -24,7 +24,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 +46,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 +55,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
122 changes: 0 additions & 122 deletions main/led_controller.c

This file was deleted.

8 changes: 0 additions & 8 deletions main/led_controller.h

This file was deleted.

Loading
Loading