Skip to content

Commit

Permalink
Merge pull request #13 from Msq001/master
Browse files Browse the repository at this point in the history
clean up frame, add TFT35 V2.0
  • Loading branch information
bigtreetech authored Jul 31, 2019
2 parents ff1be93 + 16763cc commit da072ce
Show file tree
Hide file tree
Showing 163 changed files with 3,426 additions and 1,060 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 11 additions & 15 deletions TFT/src/User/API/LCD_Encoder.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "LCD_Encoder.h"
#include "GPIO_Init.h"
#include "includes.h"

#ifdef LCD_ENCODER_SUPPORT
#if LCD_ENCODER_SUPPORT

int8_t encoderDirection = 1;
volatile int8_t encoderDiff; // Updated in update_buttons, added to encoderPosition every LCD update
Expand All @@ -10,35 +11,29 @@ uint8_t buttons = 0;

void LCD_EncoderInit(void)
{
GPIO_TypeDef *encPort[] = {LCD_ENCA_PORT, LCD_ENCB_PORT, LCD_BTN_PORT};
uint16_t encPin[] = {LCD_ENCA_PIN, LCD_ENCB_PIN, LCD_BTN_PIN};
GPIO_InitTypeDef GPIO_InitStructure;
uint16_t encPin[] = {LCD_ENCA_PIN, LCD_ENCB_PIN, LCD_BTN_PIN};

RCC_APB2PeriphClockCmd(LCD_ENCODER_RCC, ENABLE);

for(u8 i = 0; i < aCount(encPort); i++)
for(u8 i = 0; i < aCount(encPin); i++)
{
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Pin = encPin[i];
GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz;
GPIO_Init(encPort[i], &GPIO_InitStructure);
GPIO_InitSet(encPin[i], MGPIO_MODE_IPU, 0);
}
}

bool LCD_ReadEncA(void)
{
return !GPIO_ReadInputDataBit(LCD_ENCA_PORT, LCD_ENCA_PIN);
return !GPIO_GetLevel(LCD_ENCA_PIN);
}

bool LCD_ReadEncB(void)
{
return !GPIO_ReadInputDataBit(LCD_ENCB_PORT, LCD_ENCB_PIN);
return !GPIO_GetLevel(LCD_ENCB_PIN);
}

bool LCD_ReadBtn(uint8_t intervals)
{
static u32 nowTime = 0;

if(!GPIO_ReadInputDataBit(LCD_BTN_PORT, LCD_BTN_PIN))
if(!GPIO_GetLevel(LCD_BTN_PIN))
{
if(OS_GetTime() - nowTime > intervals)
{
Expand Down Expand Up @@ -92,7 +87,8 @@ void LCD_LoopEncoder(void)
}

void loopCheckMode(void)
{
{
if(isPrinting()) return;
if(LCD_ReadBtn(LCD_CHANGE_MODE_INTERVALS))
{
infoMenu.menu[++infoMenu.cur] = menuMode;
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/API/Language/Language.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define _LANGUAGE_H_

#include "stdbool.h"
#include "stm32f10x.h"
#include "variants.h"


enum
Expand Down
26 changes: 13 additions & 13 deletions TFT/src/User/API/Language/language_jp.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
#define JP_FAST_SPEED "早め"
#define JP_FAN_FULL_SPEED "全速"
#define JP_FAN_HALF_SPEED "50%速さ"
#define JP_POWER_OFF "Power Off"
#define JP_POWER_OFF "電源OFF"
#define JP_TOUCHSCREEN_ADJUST "校正する"
#define JP_SCREEN_INFO "ついて"
#define JP_DISCONNECT "データ接続"
#define JP_BAUDRATE_115200 "115200"
#define JP_BAUDRATE_250000 "250000"
#define JP_PERCENTAGE "Percentage"
#define JP_BABYSTEP "BabyStep"
#define JP_PERCENTAGE_SPEED "スビード%"
#define JP_PERCENTAGE_FLOW "押出%"
#define JP_VALUE_ZERO "Zero"
#define JP_PERCENTAGE "パーセント"
#define JP_BABYSTEP "ベビーステップ"
#define JP_PERCENTAGE_SPEED "スビード"
#define JP_PERCENTAGE_FLOW "押出"
#define JP_VALUE_ZERO "ゼロ"
#define JP_1_DEGREE "1℃"
#define JP_5_DEGREE "5℃"
#define JP_10_DEGREE "10℃"
Expand Down Expand Up @@ -65,28 +65,28 @@
#define JP_UNCONNECTED "プリンターに連続していない!"
#define JP_DISCONNECT_INFO "SDカード PC両用"
#define JP_LOADING "ロッド中..."
#define JP_POWER_FAILED "Continue printing?"
#define JP_POWER_FAILED "プリントを継続しますか?"
#define JP_CONTINUE "継続"
#define JP_CANNEL "キャンセル"
#define JP_ADJUST_TITLE "タッチスクリーン較正"
#define JP_ADJUST_INFO "赤星をタッチ"
#define JP_ADJUST_OK "校正が成功しました"
#define JP_ADJUST_FAILED "校正が失敗しました、も一度お試して下さい"
#define JP_WARNING "Warning"
#define JP_WARNING "注意"
#define JP_STOP_PRINT "プリントを中止しますか?"
#define JP_CONFIRM "確定"
#define JP_CONFIRM "OK"

#define JP_TFTSD "TFT SD"
#define JP_READ_TFTSD_ERROR "TFT SDカードの読み取りがエラー発生しました!"
#define JP_TFTSD_INSERTED "SDカード入りました!"
#define JP_TFTSD_REMOVED "SDカード出しました!"

#define JP_U_DISK "U Disk"
#define JP_READ_U_DISK_ERROR "Read U Disk error!"
#define JP_U_DISK "USBメモリー"
#define JP_READ_U_DISK_ERROR "USBメモリー読み込みエラー!"
#define JP_U_DISK_INSERTED "U Diskカード入りました!"
#define JP_U_DISK_REMOVED "U Diskカード出しました!"

#define JP_ONBOARDSD "OnboardSD"
#define JP_READ_ONBOARDSD_ERROR "Onboard SDカードの読み取りがエラー発生しました!"
#define JP_ONBOARDSD "内部 mSDカード"
#define JP_READ_ONBOARDSD_ERROR "内部 mSDカードの読み取りがエラー発生しました!"

#endif
6 changes: 4 additions & 2 deletions TFT/src/User/API/UI/ST7920_Simulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "includes.h"
#include "GUI.h"

#ifdef ST7920_SPI

ST7920_PIXEL st7920 = {ST7920_XSTART, ST7920_YSTART, 0};
ST7920_CTRL_STATUS status = ST7920_IDLE;
Expand Down Expand Up @@ -132,16 +133,17 @@ void menuST7920(void)

while(infoMenu.menu[infoMenu.cur] == menuST7920)
{
if(SPISlave.rIndex != SPISlave.wIndex)
while(SPISlave.rIndex != SPISlave.wIndex)
{
ST7920_ParseRecv(SPISlave.data[SPISlave.rIndex]);

SPISlave.rIndex = (SPISlave.rIndex + 1) % SPI_SLAVE_MAX;
}

#ifdef LCD_ENCODER_SUPPORT
#if LCD_ENCODER_SUPPORT
loopCheckMode();
#endif
}
SPI_SlaveDeInit();
}
#endif
51 changes: 20 additions & 31 deletions TFT/src/User/API/UI/touch_process.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "touch_process.h"
#include "GPIO_Init.h"
#include "includes.h"

#define XL1 LCD_X[0]
Expand Down Expand Up @@ -140,7 +141,7 @@ u16 Key_value(u8 total_rect,const GUI_RECT* menuRect)
{
if((x>menuRect[i].x0)&&(x<menuRect[i].x1)&&(y>menuRect[i].y0)&&(y<menuRect[i].y1))
{
#ifdef BUZZER_SUPPORT
#ifdef BUZZER_PIN
openBuzzer(3, 11);
#endif
return i;
Expand Down Expand Up @@ -385,7 +386,7 @@ u16 KNOB_GetRV(GUI_RECT *knob)
return key_return;
}

#ifdef BUZZER_SUPPORT
#ifdef BUZZER_PIN
void TIM3_Config(u16 psc,u16 arr)
{
NVIC_InitTypeDef NVIC_InitStructure;
Expand All @@ -396,36 +397,25 @@ void TIM3_Config(u16 psc,u16 arr)
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

RCC->APB1ENR|=1<<1; //TIM3时钟使能
TIM3->ARR=arr; //设定自动重装值
TIM3->PSC=psc; //预分频器
TIM3->SR = (uint16_t)~(1<<0); //清除更新中断
TIM3->DIER|=1<<0; //允许更新中断
RCC->APB1ENR|=1<<1; //TIM3ʱ��ʹ��
TIM3->ARR=arr; //�趨�Զ���װֵ
TIM3->PSC=psc; //Ԥ��Ƶ��
TIM3->SR = (uint16_t)~(1<<0); //��������ж�
TIM3->DIER|=1<<0; //���������ж�
TIM3->CNT =0;
TIM3->CR1 &= ~(0x01); //失能定时器3
TIM3->CR1 &= ~(0x01); //ʧ�ܶ�ʱ��3
}

void Buzzer_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;

RCC_APB2PeriphClockCmd(BUZZER_RCC, ENABLE);

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = BUZZER_PIN;
GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz;
GPIO_Init(BUZZER_PORT, &GPIO_InitStructure);
{
GPIO_InitSet(BUZZER_PIN, MGPIO_MODE_OUT_PP, 0);

TIM3_Config(719,100); //1Khz
TIM3_Config(999, F_CPUM-1); //1Khz
}

void Buzzer_DeConfig(void)
{
GPIO_InitTypeDef GPIO_InitStructure;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = BUZZER_PIN;
GPIO_Init(BUZZER_PORT, &GPIO_InitStructure);
GPIO_InitSet(BUZZER_PIN, MGPIO_MODE_IPN, 0);
}

typedef struct{
Expand All @@ -446,38 +436,37 @@ void openBuzzer(u16 h_us, u16 l_us)
else
buzzer.num = 500;

TIM3->CR1 |= 0x01; //使能定时器3
TIM3->CR1 |= 0x01; //ʹ�ܶ�ʱ��3
}
void closeBuzzer(void)
{
buzzer.num = 0;
TIM3->CR1 &= ~(0x01);
}

void TIM3_IRQHandler(void) //TIM3中断
void TIM3_IRQHandler(void) //TIM3�ж�
{
static bool flag = false;
if ((TIM3->SR&0x01) != 0 ) //检查指定的TIM中断发生与否:TIM 中断源
if ((TIM3->SR&0x01) != 0 ) //���ָ����TIM�жϷ������:TIM �ж�Դ
{
flag = !flag;
flag = !flag;
if( flag )
{
GPIO_SetBits(BUZZER_PORT, BUZZER_PIN);
TIM3->ARR = buzzer.h_us;
}
else
{
GPIO_ResetBits(BUZZER_PORT, BUZZER_PIN);
TIM3->ARR = buzzer.l_us;
}


GPIO_SetLevel(BUZZER_PIN, flag);
buzzer.num--;
if( buzzer.num == 0 )
{
TIM3->CR1 &= ~(0x01);
}

TIM3->SR = (uint16_t)~(1<<0); //清除TIMx的中断待处理位:TIM 中断源
TIM3->SR = (uint16_t)~(1<<0); //���TIMx���жϴ�����λ:TIM �ж�Դ
}
}
#endif
94 changes: 1 addition & 93 deletions TFT/src/User/API/UI/ui_draw.c
Original file line number Diff line number Diff line change
@@ -1,101 +1,9 @@
#include "ui_draw.h"
#include "includes.h"




#ifdef STM32_HAS_FSMC
//Config for SPI Channel
#if W25Qxx_SPI == _SPI1
#define W25QXX_SPI_NUM SPI1
#define W25QXX_SPI_DMA_RCC_AHB RCC_AHBPeriph_DMA1
#define W25QXX_SPI_DMA DMA1
#define W25QXX_SPI_DMA_CHANNEL DMA1_Channel2
#define W25QXX_SPI_DMA_IFCR_BIT 5
#elif W25Qxx_SPI == _SPI2
#define W25QXX_SPI_NUM SPI2
#define W25QXX_SPI_DMA DMA1
#define W25QXX_SPI_DMA_RCC_AHB RCC_AHBPeriph_DMA1
#define W25QXX_SPI_DMA_CHANNEL DMA1_Channel4
#define W25QXX_SPI_DMA_IFCR_BIT 13
#elif W25Qxx_SPI == _SPI3
#define W25QXX_SPI_NUM SPI3
#define W25QXX_SPI_DMA DMA2
#define W25QXX_SPI_DMA_RCC_AHB RCC_AHBPeriph_DMA2
#define W25QXX_SPI_DMA_CHANNEL DMA2_Channel1
#define W25QXX_SPI_DMA_IFCR_BIT 1
#endif

//SPI --> FSMC DMA (LCD_RAM)
//16bits, SPI_RX to LCD_RAM.
void LCD_DMA_Config(void)
{

RCC->AHBENR |= W25QXX_SPI_DMA_RCC_AHB; //开启DMA时钟
Delay_ms(5); //等待DMA时钟稳定
W25QXX_SPI_DMA_CHANNEL->CPAR = (u32)&W25QXX_SPI_NUM->DR; //外设地址为:SPI->DR
W25QXX_SPI_DMA_CHANNEL->CMAR = (u32)&LCD->LCD_RAM;//目标地址为LCD_RAM
W25QXX_SPI_DMA_CHANNEL->CNDTR = 0; //DMA1,传输数据量,暂时设置为0
W25QXX_SPI_DMA_CHANNEL->CCR = 0X00000000; //复位
W25QXX_SPI_DMA_CHANNEL->CCR |= 0<<4; //从外设读
W25QXX_SPI_DMA_CHANNEL->CCR |= 0<<5; //普通模式
W25QXX_SPI_DMA_CHANNEL->CCR |= 0<<6; //外设地址非增量模式
W25QXX_SPI_DMA_CHANNEL->CCR |= 0<<7; //存储器非增量模式
W25QXX_SPI_DMA_CHANNEL->CCR |= LCD_DATA_16BIT<<8; //外设数据宽度为16位
W25QXX_SPI_DMA_CHANNEL->CCR |= LCD_DATA_16BIT<<10; //存储器数据宽度16位
W25QXX_SPI_DMA_CHANNEL->CCR |= 1<<12; //中等优先级
W25QXX_SPI_DMA_CHANNEL->CCR |= 0<<14; //非存储器到存储器模式
}

#define LCD_DMA_MAX_TRANS 65535 //DMA 65535 bytes one frame
// start DMA transfer from SPI->DR to FSMC
// the max bytes of one frame is LCD_DMA_MAX_TRANS 65535
void lcd_frame_segment_display(u16 size, u32 addr)
{
W25QXX_SPI_DMA_CHANNEL->CNDTR = size;

W25Qxx_SPI_CS_Set(0);
W25Qxx_SPI_Read_Write_Byte(CMD_FAST_READ_DATA);
W25Qxx_SPI_Read_Write_Byte((u8)((addr)>>16));
W25Qxx_SPI_Read_Write_Byte((u8)((addr)>>8));
W25Qxx_SPI_Read_Write_Byte((u8)addr);
W25Qxx_SPI_Read_Write_Byte(0XFF); //8 dummy clock

//set SPI to 16bit DMA rx only mode
W25QXX_SPI_NUM->CR1 &= ~(1<<6);
W25QXX_SPI_NUM->CR2 |= 1<<0; //enable SPI rx DMA
W25QXX_SPI_NUM->CR1 |= LCD_DATA_16BIT<<11; //16bit data frame
W25QXX_SPI_NUM->CR1 |= 1<<10; //rx only

W25QXX_SPI_DMA_CHANNEL->CCR |= 1<<0; //enable dma channel
W25QXX_SPI_NUM->CR1 |= 1<<6; //enable SPI

while((W25QXX_SPI_DMA->ISR&(1<<W25QXX_SPI_DMA_IFCR_BIT)) == 0); //wait for rx complete
W25QXX_SPI_DMA_CHANNEL->CCR &= (u32)(~(1<<0));
W25QXX_SPI_DMA->IFCR |= (u32)(1<<W25QXX_SPI_DMA_IFCR_BIT); //clear ISR for rx complete
W25Qxx_SPI_CS_Set(1);

//set spi from dma to normal mode
// RCC->APB1RSTR |= 1<<15; //reset SPI
// RCC->APB1RSTR &= ~(1<<15);
SPI_Protocol_Init(W25Qxx_SPI, W25Qxx_SPEED);
}

void lcd_frame_display(u16 sx,u16 sy,u16 w,u16 h, u32 addr)
{
u32 cur=0;
u32 segmentSize;
u32 totalSize = w*h*(2-LCD_DATA_16BIT);

LCD_SetWindow(sx,sy,sx+w-1,sy+h-1);
LCD_WR_REG(0x2C);

for(cur = 0; cur < totalSize; cur += LCD_DMA_MAX_TRANS)
{
segmentSize = cur+LCD_DMA_MAX_TRANS<=totalSize ? LCD_DMA_MAX_TRANS : totalSize-cur;
lcd_frame_segment_display(segmentSize, addr+cur*(LCD_DATA_16BIT + 1));
}
}
void lcd_frame_display(u16 sx,u16 sy,u16 w,u16 h, u32 addr);

#else

Expand Down
4 changes: 2 additions & 2 deletions TFT/src/User/API/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool bmpDecode(char *bmp,u32 addr)
f_read(&bmpFile, magic, 2 ,&mybr);
if (memcmp(magic, "BM", 2))
return false;
//****************��ȡͷ��Ϣ****************//

f_lseek(&bmpFile, 10);
f_read(&bmpFile, &offset, sizeof(int),&mybr);

Expand All @@ -71,7 +71,7 @@ bool bmpDecode(char *bmp,u32 addr)
return false;
bpp >>=3;
bytePerLine=w*bpp;
if(bytePerLine%4 !=0) //bmp�ļ�ÿ�е��ֽ��������� 4 ����������������ǣ�����Ҫ����
if(bytePerLine%4 !=0) //bmp
bytePerLine=(bytePerLine/4+1)*4;

for(bnum=0;bnum<(w*h*2+4095)/4096;bnum++)
Expand Down
Loading

0 comments on commit da072ce

Please sign in to comment.