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

LCD Feature #906

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
113 changes: 113 additions & 0 deletions soccer_hardware/soccer_firmware/Core/Inc/fonts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
******************************************************************************
* @file fonts.h
* @author MCD Application Team
* @brief This file provides definition for fonts to be used for STM32
* board's LCD driver
******************************************************************************
* @attention
*
* Copyright (c) 2014 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __FONTS_H
#define __FONTS_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include <stdint.h>

/** @addtogroup Utilities
* @{
*/

/** @addtogroup STM32_EVAL
* @{
*/

/** @addtogroup Common
* @{
*/

/** @addtogroup FONTS
* @{
*/

/** @defgroup FONTS_Exported_Types
* @{
*/
typedef struct _tFont
{
const uint8_t *table;
uint16_t Width;
uint16_t Height;
} sFONT;

extern sFONT Font24;
extern sFONT Font20;
extern sFONT Font16;
extern sFONT Font12;
extern sFONT Font8;
/**
* @}
*/

/** @defgroup FONTS_Exported_Constants
* @{
*/
#define LINE(x) ((x) * (((sFONT *)BSP_LCD_GetFont())->Height))

/**
* @}
*/

/** @defgroup FONTS_Exported_Macros
* @{
*/
/**
* @}
*/

/** @defgroup FONTS_Exported_Functions
* @{
*/
/**
* @}
*/

#ifdef __cplusplus
}
#endif

#endif /* __FONTS_H */

/**
* @}
*/

/**
* @}
*/

/**
* @}
*/

/**
* @}
*/

/**
* @}
*/
2 changes: 0 additions & 2 deletions soccer_hardware/soccer_firmware/Core/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ void Error_Handler(void);
#define USART3_DIR_GPIO_Port GPIOB
#define USART6_DIR_Pin GPIO_PIN_15
#define USART6_DIR_GPIO_Port GPIOB
#define USART1_DIR_Pin GPIO_PIN_8
#define USART1_DIR_GPIO_Port GPIOA
#define GREEN_LED_Pin GPIO_PIN_15
#define GREEN_LED_GPIO_Port GPIOA
#define USART5_DIR_Pin GPIO_PIN_4
Expand Down
17 changes: 17 additions & 0 deletions soccer_hardware/soccer_firmware/Core/Inc/ssd1306.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* ssd1306.h
*
* Created on: Oct 19, 2024
* Author: ozodm
*/

/* SSD1306 width in pixels */
#ifndef SSD1306_WIDTH
#define SSD1306_WIDTH 128
#endif
/* SSD1306 LCD height in pixels */
#ifndef SSD1306_HEIGHT
#define SSD1306_HEIGHT 64
#endif


10 changes: 5 additions & 5 deletions soccer_hardware/soccer_firmware/Core/Inc/stm32f4xx_hal_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,15 @@
#define MAC_ADDR5 0U

/* Definition of the Ethernet driver buffers size and count */
#define ETH_RX_BUF_SIZE /* buffer size for receive */
#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
#define ETH_RXBUFNB 4U /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
#define ETH_TXBUFNB 4U /* 4 Tx buffers of size ETH_TX_BUF_SIZE */

/* Section 2: PHY configuration section */

/* DP83848_PHY_ADDRESS Address*/
#define DP83848_PHY_ADDRESS 0x01U
#define DP83848_PHY_ADDRESS
/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/
#define PHY_RESET_DELAY 0x000000FFU
/* PHY Configuration delay */
Expand Down Expand Up @@ -252,10 +252,10 @@
#define PHY_JABBER_DETECTION ((uint16_t)0x0002U) /*!< Jabber condition detected */

/* Section 4: Extended PHY Registers */
#define PHY_SR ((uint16_t)0x10U) /*!< PHY status register Offset */
#define PHY_SR ((uint16_t)) /*!< PHY status register Offset */

#define PHY_SPEED_STATUS ((uint16_t)0x0002U) /*!< PHY Speed mask */
#define PHY_DUPLEX_STATUS ((uint16_t)0x0004U) /*!< PHY Duplex mask */
#define PHY_SPEED_STATUS ((uint16_t)) /*!< PHY Speed mask */
#define PHY_DUPLEX_STATUS ((uint16_t)) /*!< PHY Duplex mask */

/* ################## SPI peripheral configuration ########################## */

Expand Down
2 changes: 0 additions & 2 deletions soccer_hardware/soccer_firmware/Core/Inc/stm32f4xx_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void DMA1_Stream0_IRQHandler(void);
void DMA1_Stream1_IRQHandler(void);
void DMA1_Stream2_IRQHandler(void);
void DMA1_Stream3_IRQHandler(void);
void DMA1_Stream4_IRQHandler(void);
void DMA1_Stream5_IRQHandler(void);
void DMA1_Stream6_IRQHandler(void);
Expand Down
101 changes: 88 additions & 13 deletions soccer_hardware/soccer_firmware/Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "usb_device.h"
#include "../../Drivers/OLED/ssd1306_fonts.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
Expand All @@ -32,7 +33,8 @@

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

extern I2C_HandleTypeDef hi2c1;
#define SSD1306_I2C &hi2c1
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
Expand All @@ -42,6 +44,7 @@

/* Private variables ---------------------------------------------------------*/
I2C_HandleTypeDef hi2c1;
I2C_HandleTypeDef hi2c2;

UART_HandleTypeDef huart4;
UART_HandleTypeDef huart5;
Expand Down Expand Up @@ -83,13 +86,15 @@ static void MX_USART2_UART_Init(void);
static void MX_USART3_UART_Init(void);
static void MX_USART6_UART_Init(void);
static void MX_I2C1_Init(void);
static void MX_I2C2_Init(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
// test various functionalities
/*
void init_ports() {
// port1 => UART1 ==> J2 on new PCB
port1 = (MotorPort){
Expand Down Expand Up @@ -207,7 +212,7 @@ void init_motors() {
// slowly bring motors to zero position
}
}

*/
/* USER CODE END 0 */

/**
Expand Down Expand Up @@ -247,16 +252,34 @@ int main(void)
MX_USART3_UART_Init();
MX_USART6_UART_Init();
MX_I2C1_Init();
MX_I2C2_Init();
/* USER CODE BEGIN 2 */
// give some time for motors to power on and initialize, before we try to talk to them
HAL_Delay(1000);

init_ports();
// MPU6050_init();
init_motors();
// char myText[] = "Robosoccer";
char retVal;
uint32_t lastTime;
uint32_t startTime;
uint32_t time;
char myText[50];

ssd1306_Init();
//// ssd1306_Fill(0x01);


BMI088 imu;
BMI088_Init(&imu, &hi2c1);
ssd1306_SetCursor(5,5);
// retVal = ssd1306_WriteString(myText, Font_7x10, 0x01);
// ssd1306_UpdateScreen();

// give some time for motors to power on and initialize, before we try to talk to them

// HAL_Delay(1000);
//
// init_ports();
//// MPU6050_init();
// init_motors();
//
// BMI088 imu;
// BMI088_Init(&imu, &hi2c1);

// uint16_t angle = 0;
// uint16_t angle_lo = 0;
Expand All @@ -268,8 +291,26 @@ int main(void)
/* USER CODE BEGIN WHILE */
while (1)
{
startTime = HAL_GetTick();

HAL_Delay(1000);

lastTime = HAL_GetTick();

time = lastTime - startTime;

memset(myText, '\0', sizeof(myText)); // Clear the array (set all elements to '\0')
sprintf(myText, "%d", time); // Format lastTime into myText

ssd1306_Fill(0x00);
ssd1306_SetCursor(5,5);
retVal = ssd1306_WriteString(myText, Font_7x10, 0x01);
ssd1306_UpdateScreen();



update();

// update();

// angle += 1;
// angle %= 0x3FF;
Expand Down Expand Up @@ -417,6 +458,40 @@ static void MX_I2C1_Init(void)

}

/**
* @brief I2C2 Initialization Function
* @param None
* @retval None
*/
static void MX_I2C2_Init(void)
{

/* USER CODE BEGIN I2C2_Init 0 */

/* USER CODE END I2C2_Init 0 */

/* USER CODE BEGIN I2C2_Init 1 */

/* USER CODE END I2C2_Init 1 */
hi2c2.Instance = I2C2;
hi2c2.Init.ClockSpeed = 100000;
hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2;
hi2c2.Init.OwnAddress1 = 0;
hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c2.Init.OwnAddress2 = 0;
hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
if (HAL_I2C_Init(&hi2c2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN I2C2_Init 2 */

/* USER CODE END I2C2_Init 2 */

}

/**
* @brief UART4 Initialization Function
* @param None
Expand Down Expand Up @@ -687,7 +762,7 @@ static void MX_GPIO_Init(void)
HAL_GPIO_WritePin(USART4_DIR_GPIO_Port, USART4_DIR_Pin, GPIO_PIN_RESET);

/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, USART2_DIR_Pin|USART1_DIR_Pin|GREEN_LED_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOA, USART2_DIR_Pin|GPIO_PIN_8|GREEN_LED_Pin, GPIO_PIN_RESET);

/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, USART3_DIR_Pin|USART6_DIR_Pin|USART5_DIR_Pin, GPIO_PIN_RESET);
Expand All @@ -699,8 +774,8 @@ static void MX_GPIO_Init(void)
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(USART4_DIR_GPIO_Port, &GPIO_InitStruct);

/*Configure GPIO pins : USART2_DIR_Pin USART1_DIR_Pin GREEN_LED_Pin */
GPIO_InitStruct.Pin = USART2_DIR_Pin|USART1_DIR_Pin|GREEN_LED_Pin;
/*Configure GPIO pins : USART2_DIR_Pin PA8 GREEN_LED_Pin */
GPIO_InitStruct.Pin = USART2_DIR_Pin|GPIO_PIN_8|GREEN_LED_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
Expand Down
Loading
Loading