#define CTR_OSC_START 0x0000 #define CTR_DRV_OUTPUT1 0x0001 #define CTR_DRV_WAVE 0x0002 #define CTR_ENTRY_MODE 0x0003 #define CTR_RESIZE 0x0004 #define CTR_DISPLAY1 0x0007 #define CTR_DISPLAY2 0x0008 #define CTR_DISPLAY3 0x0009 #define CTR_DISPLAY4 0x000A #define CTR_RGB_INTERFACE1 0x000C #define CTR_FRM_MARKER 0x000D #define CTR_RGB_INTERFACE2 0x000F #define CTR_POWER1 0x0010 #define CTR_POWER2 0x0011 #define CTR_POWER3 0x0012 #define CTR_POWER4 0x0013 #define CTR_HORZ_ADDRESS 0x0020 #define CTR_VERT_ADDRESS 0x0021 #define CTR_WRITE_DATA 0x0022 #define CTR_READ_DATA 0x0022 #define CTR_POWER7 0x0029 #define CTR_FRM_COLOR 0x002B #define CTR_GAMMA1 0x0030 #define CTR_GAMMA2 0x0031 #define CTR_GAMMA3 0x0032 #define CTR_GAMMA4 0x0035 #define CTR_GAMMA5 0x0036 #define CTR_GAMMA6 0x0037 #define CTR_GAMMA7 0x0038 #define CTR_GAMMA8 0x0039 #define CTR_GAMMA9 0x003C #define CTR_GAMMA10 0x003D #define CTR_HORZ_START 0x0050 #define CTR_HORZ_END 0x0051 #define CTR_VERT_START 0x0052 #define CTR_VERT_END 0x0053 #define CTR_DRV_OUTPUT2 0x0060 #define CTR_BASE_IMAGE 0x0061 #define CTR_VERT_SCROLL 0x006A #define CTR_PIMG1_POS 0x0080 #define CTR_PIMG1_START 0x0081 #define CTR_PIMG1_END 0x0082 #define CTR_PIMG2_POS 0x0083 #define CTR_PIMG2_START 0x0084 #define CTR_PIMG2_END 0x0085 #define CTR_PANEL_INTERFACE1 0x0090 #define CTR_PANEL_INTERFACE2 0x0092 #define CTR_PANEL_INTERFACE4 0x0095 #define CTR_OTP_VCMPROGRAM 0x00A1 #define CTR_OTP_VCMSTATUS 0x00A2 #define CTR_OTP_IDKEY 0x00A5
#define LCDRegister (*((volatile uint16_t*) 0x60000000))
#define LCDMemory (*((volatile uint16_t*) 0x60020000))
#define LCD_WRITE_REGISTER(REG, DATA) LCDRegister=REG;LCDMemory=DATA; #define LCD_BEGIN_RAM_WRITE LCDRegister=CTR_WRITE_DATA; #define LCD_WRITE_RAM(DATA) LCDMemory=DATA
#define BacklightPin GPIO_Pin_13 #define BacklightPort GPIOD #define ResetPin GPIO_Pin_1 #define ResetPort GPIOE
void LCDInitHardware() { SysTick_Config(SystemCoreClock/1000); GPIO_InitTypeDef GPIO_InitStructure; FSMC_NORSRAMInitTypeDef FSMC_InitStructure; FSMC_NORSRAMTimingInitTypeDef FSMC_Timing; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10| GPIO_Pin_11| GPIO_Pin_14| GPIO_Pin_15; //Interface GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11| GPIO_Pin_12| GPIO_Pin_13| GPIO_Pin_14 | GPIO_Pin_15; //Interface GPIO_Init(GPIOE, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = BacklightPin; //Backlight GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(BacklightPort, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = ResetPin; //Reset GPIO_Init(ResetPort, &GPIO_InitStructure); GPIO_SetBits(ResetPort,ResetPin); FSMC_Timing.FSMC_AddressSetupTime = 1; FSMC_Timing.FSMC_AddressHoldTime = 0; FSMC_Timing.FSMC_DataSetupTime = 5; FSMC_Timing.FSMC_BusTurnAroundDuration = 0; FSMC_Timing.FSMC_CLKDivision = 0; FSMC_Timing.FSMC_DataLatency = 0; FSMC_Timing.FSMC_AccessMode = FSMC_AccessMode_B; FSMC_InitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; FSMC_InitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; FSMC_InitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; FSMC_InitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; FSMC_InitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; FSMC_InitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; FSMC_InitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; FSMC_InitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; FSMC_InitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; FSMC_InitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; FSMC_InitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; FSMC_InitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; FSMC_InitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; FSMC_InitStructure.FSMC_ReadWriteTimingStruct = &FSMC_Timing; FSMC_InitStructure.FSMC_WriteTimingStruct = &FSMC_Timing; FSMC_NORSRAMInit(&FSMC_InitStructure); FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); }
volatile uint32_t Tick = 0x00000000; void SysTick_Handler() { if(Tick>0) Tick--; } void SysTickDelay(uint32_t msDelay) { Tick=msDelay; while(Tick); }
void LCDInit() { LCDHardwareReset(); LCD_WRITE_REGISTER(CTR_OSC_START, 0x0001); LCD_WRITE_REGISTER(CTR_DRV_OUTPUT1, 0x0100); LCD_WRITE_REGISTER(CTR_DRV_WAVE, 0x0700); LCD_WRITE_REGISTER(CTR_ENTRY_MODE, 0x1038); LCD_WRITE_REGISTER(CTR_RESIZE, 0x0000); LCD_WRITE_REGISTER(CTR_DISPLAY2, 0x0202); LCD_WRITE_REGISTER(CTR_DISPLAY3, 0x0000); LCD_WRITE_REGISTER(CTR_DISPLAY4, 0x0000); LCD_WRITE_REGISTER(CTR_RGB_INTERFACE1, 0x0001); LCD_WRITE_REGISTER(CTR_FRM_MARKER, 0x0000); LCD_WRITE_REGISTER(CTR_RGB_INTERFACE2, 0x0000); LCD_WRITE_REGISTER(CTR_POWER1, 0x0000); LCD_WRITE_REGISTER(CTR_POWER2, 0x0007); LCD_WRITE_REGISTER(CTR_POWER3, 0x0000); LCD_WRITE_REGISTER(CTR_POWER4, 0x0000); SysTickDelay(200); LCD_WRITE_REGISTER(CTR_POWER1, 0x1590); LCD_WRITE_REGISTER(CTR_POWER2, 0x0227); SysTickDelay(50); LCD_WRITE_REGISTER(CTR_POWER3, 0x009C); SysTickDelay(50); LCD_WRITE_REGISTER(CTR_POWER4, 0x1900); LCD_WRITE_REGISTER(CTR_POWER7, 0x1900); LCD_WRITE_REGISTER(CTR_FRM_COLOR, 0x000E); SysTickDelay(50); LCD_WRITE_REGISTER(CTR_HORZ_ADDRESS, 0x0000); LCD_WRITE_REGISTER(CTR_VERT_ADDRESS, 0x0000); LCD_WRITE_REGISTER(CTR_HORZ_START, 0x0000); LCD_WRITE_REGISTER(CTR_HORZ_END, 239); LCD_WRITE_REGISTER(CTR_VERT_START, 0x0000); LCD_WRITE_REGISTER(CTR_VERT_END, 319); LCD_WRITE_REGISTER(CTR_DRV_OUTPUT2, 0x2700); LCD_WRITE_REGISTER(CTR_BASE_IMAGE, 0x0001); LCD_WRITE_REGISTER(CTR_VERT_SCROLL, 0x0000); GPIO_SetBits(BacklightPort,BacklightPin); }
void LCDHardwareReset() { GPIO_ResetBits(ResetPort,ResetPin); SysTickDelay(50); GPIO_SetBits(ResetPort,ResetPin); SysTickDelay(10); }
void LCDOn() { LCD_WRITE_REGISTER(CTR_DISPLAY1, 0x0133); } void LCDOff() { LCD_WRITE_REGISTER(CTR_DISPLAY1, 0x0131); }
void LCDSetBounds(uint16_t left, uint16_t top, uint16_t right, uint16_t bottom) { LCD_WRITE_REGISTER(CTR_VERT_START, left); LCD_WRITE_REGISTER(CTR_VERT_END, right); LCD_WRITE_REGISTER(CTR_HORZ_START, top); LCD_WRITE_REGISTER(CTR_HORZ_END, bottom); LCD_WRITE_REGISTER(CTR_HORZ_ADDRESS, top); LCD_WRITE_REGISTER(CTR_VERT_ADDRESS, left); }
void LCDClear(uint16_t color) { LCDSetBounds(0,0,320-1,240-1); LCD_BEGIN_RAM_WRITE; uint32_t i; for(i=0;i<320*240;i++) LCD_WRITE_RAM(color); }
LCDInitHardware(); LCDInit(); LCDOn(); LCDClear(0x0000);
#include "stm32f10x.h"
#include "usb_lib.h" #define SIZ_DEVICE_DESC 0x12 #define SIZ_CONFIG_DESC 0x19 #define SIZ_STRING_LANGID 0x04 #define SIZ_STRING_VENDOR 0x10 #define SIZ_STRING_PRODUCT 0x10 #define SIZ_STRING_SERIAL 0x12 extern const uint8_t USB_ConfigDescriptor[SIZ_CONFIG_DESC]; extern ONE_DESCRIPTOR Device_Descriptor; extern ONE_DESCRIPTOR Config_Descriptor; extern ONE_DESCRIPTOR String_Descriptor[4];
const uint8_t USB_DeviceDescriptor[SIZ_DEVICE_DESC] = { 0x12, /* bLength */ 0x01, /* bDescriptorType */ 0x00, 0x02, /* bcdUSB = 2.00 */ 0xFF, /* bDeviceClass: Vendor Specific */ 0x00, /* bDeviceSubClass */ 0x00, /* bDeviceProtocol */ 0x40, /* bMaxPacketSize0 */ 0xAD, 0xDE, /* idVendor*/ 0x0D, 0xF0, /* idProduct*/ 0x00, 0x01, /* bcdDevice = 2.00 */ 1, /* Index of string descriptor describing manufacturer */ 2, /* Index of string descriptor describing product */ 3, /* Index of string descriptor describing the device's serial number */ 0x01 /* bNumConfigurations */ };
const uint8_t USB_ConfigDescriptor[SIZ_CONFIG_DESC] = { /*Configuration Descriptor*/ 0x09, /* bLength: Configuration Descriptor size */ 0x02, /* bDescriptorType: Configuration */ SIZ_CONFIG_DESC, /* wTotalLength:no of returned bytes */ 0x00, 0x01, /* bNumInterfaces: 1 interface */ 0x01, /* bConfigurationValue: Configuration value */ 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ 0xE0, /* bmAttributes: bus powered */ 0x32, /* MaxPower 100 mA */ /*Interface Descriptor*/ 0x09, /* bLength: Interface Descriptor size */ 0x04, /* bDescriptorType: Interface */ 0x00, /* bInterfaceNumber: Number of Interface */ 0x00, /* bAlternateSetting: Alternate setting */ 0x01, /* bNumEndpoints: One endpoints used */ 0xFF, /* bInterfaceClass: Vendor Specific*/ 0x00, /* bInterfaceSubClass*/ 0x00, /* bInterfaceProtocol*/ 0x00, /* iInterface: */ /*Endpoint 1 Descriptor*/ 0x07, /* bLength: Endpoint Descriptor size */ 0x05, /* bDescriptorType: Endpoint */ 0x01, /* bEndpointAddress: (OUT1) */ 0x02, /* bmAttributes: Bulk */ 0x40, /* wMaxPacketSize: */ 0x00, 0x00 /* bInterval: */ };
/* USB String Descriptors */ const uint8_t USB_StringLangID[SIZ_STRING_LANGID] = { SIZ_STRING_LANGID, /* bLength */ 0x03, /* String descriptor */ 0x09, 0x04 /* LangID = 0x0409: US English */ }; const uint8_t USB_StringVendor[SIZ_STRING_VENDOR] = { SIZ_STRING_VENDOR, /* Size of Vendor string */ 0x03, /* bDescriptorType*/ /* Manufacturer: "Amon-Ra" */ 'A', 0, 'm', 0, 'o', 0, 'n', 0, '-', 0, 'R', 0, 'a', 0 }; const uint8_t USB_StringProduct[SIZ_STRING_PRODUCT] = { SIZ_STRING_PRODUCT, /* bLength */ 0x03, /* bDescriptorType */ /* Product name: "USB LCD" */ 'U', 0, 'S', 0, 'B', 0, ' ', 0, 'L', 0, 'C', 0, 'D', 0 }; uint8_t USB_StringSerial[SIZ_STRING_SERIAL] = { SIZ_STRING_SERIAL, /* bLength */ 0x03, /* bDescriptorType */ 'U', 0, 'S', 0, 'B', 0, 'L', 0, 'C', 0, 'D', 0, '0', 0, '1', 0 };
ONE_DESCRIPTOR Device_Descriptor = { (uint8_t*)USB_DeviceDescriptor, SIZ_DEVICE_DESC }; ONE_DESCRIPTOR Config_Descriptor = { (uint8_t*)USB_ConfigDescriptor, SIZ_CONFIG_DESC }; ONE_DESCRIPTOR String_Descriptor[4] = { {(uint8_t*)USB_StringLangID, SIZ_STRING_LANGID}, {(uint8_t*)USB_StringVendor, SIZ_STRING_VENDOR}, {(uint8_t*)USB_StringProduct, SIZ_STRING_PRODUCT}, {(uint8_t*)USB_StringSerial, SIZ_STRING_SERIAL} };
#define EP_NUM 0x02 #define BTABLE_ADDRESS (0x00) /* EP0 */ /* rx/tx buffer base address */ #define ENDP0_RXADDR (0x40) #define ENDP0_TXADDR (0x80) /* EP1 */ /* tx buffer base address */ #define ENDP1_RXADDR (0xC0) /* IMR_MSK */ /* mask defining which events has to be handled */ /* by the device application software */ #define IMR_MSK (CNTR_CTRM | CNTR_RESETM)
void Device_init() { DEVICE_INFO *pInfo = &Device_Info; pInfo->Current_Configuration = 0; _SetCNTR(CNTR_FRES); //Reset USB block _SetCNTR(0); //Deassert reset signal _SetISTR(0); //Clear pending interrupts USB_SIL_Init(); GPIO_ResetBits(GPIOC, GPIO_Pin_13); //Enable pull-up }
void Device_Reset() { //Set device as not configured pInformation->Current_Configuration = 0; pInformation->Current_Interface = 0; //the default Interface /* Current Feature initialization */ pInformation->Current_Feature = USB_ConfigDescriptor[7]; SetBTABLE(BTABLE_ADDRESS); /* Initialize Endpoint 0 */ SetEPType(ENDP0, EP_CONTROL); SetEPTxStatus(ENDP0, EP_TX_STALL); SetEPRxAddr(ENDP0, ENDP0_RXADDR); SetEPTxAddr(ENDP0, ENDP0_TXADDR); Clear_Status_Out(ENDP0); SetEPRxCount(ENDP0, Device_Property.MaxPacketSize); SetEPRxValid(ENDP0); SetEPType(ENDP1, EP_BULK); SetEPRxAddr(ENDP1, ENDP1_RXADDR); SetEPRxCount(ENDP1, 0x40); SetEPRxStatus(ENDP1, EP_RX_VALID); SetEPTxStatus(ENDP1, EP_TX_DIS); /* Set this device to response on default address */ SetDeviceAddress(0); }
#define Device_Status_In NOP_Process #define Device_Status_Out NOP_Process
RESULT Device_Data_Setup(uint8_t RequestNo) { return USB_UNSUPPORT; } RESULT Device_NoData_Setup(uint8_t RequestNo) { return USB_UNSUPPORT; }
RESULT Device_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting) { if (AlternateSetting > 0) { return USB_UNSUPPORT; } else if (Interface > 0) { return USB_UNSUPPORT; } return USB_SUCCESS; }
uint8_t *Device_GetDeviceDescriptor(uint16_t Length) { return Standard_GetDescriptorData(Length, &Device_Descriptor); } uint8_t *Device_GetConfigDescriptor(uint16_t Length) { return Standard_GetDescriptorData(Length, &Config_Descriptor); } uint8_t *Device_GetStringDescriptor(uint16_t Length) { uint8_t wValue0 = pInformation->USBwValue0; if (wValue0 > 4) { return NULL; } else { return Standard_GetDescriptorData(Length, &String_Descriptor[wValue0]); } }
DEVICE_PROP Device_Property = { Device_init, Device_Reset, Device_Status_In, Device_Status_Out, Device_Data_Setup, Device_NoData_Setup, Device_Get_Interface_Setting, Device_GetDeviceDescriptor, Device_GetConfigDescriptor, Device_GetStringDescriptor, 0, 0x40 /*MAX PACKET SIZE*/ };
#define Device_GetConfiguration NOP_Process #define Device_SetConfiguration NOP_Process #define Device_GetInterface NOP_Process #define Device_SetInterface NOP_Process #define Device_GetStatus NOP_Process #define Device_ClearFeature NOP_Process #define Device_SetEndPointFeature NOP_Process #define Device_SetDeviceFeature NOP_Process #define Device_SetDeviceAddress NOP_Process USER_STANDARD_REQUESTS User_Standard_Requests = { Device_GetConfiguration, Device_SetConfiguration, Device_GetInterface, Device_SetInterface, Device_GetStatus, Device_ClearFeature, Device_SetEndPointFeature, Device_SetDeviceFeature, Device_SetDeviceAddress };
__IO uint16_t wIstr; DEVICE Device_Table = { EP_NUM, 1 };
void USB_Interrupts_Config(void) { NVIC_InitTypeDef NVIC_InitStructure; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = USB_HP_CAN1_TX_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } void Set_USBClock() { /* Select USBCLK source */ RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5); /* Enable the USB clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE); }
void USB_HP_CAN1_TX_IRQHandler(void) { CTR_HP(); } void USB_LP_CAN1_RX0_IRQHandler(void) { wIstr = _GetISTR(); #if (IMR_MSK & ISTR_CTR) if (wIstr & ISTR_CTR & wInterrupt_Mask) { CTR_LP(); } #endif #if (IMR_MSK & ISTR_RESET) if (wIstr & ISTR_RESET & wInterrupt_Mask) { _SetISTR((uint16_t)CLR_RESET); Device_Property.Reset(); } #endif }
void PMAToLCDBufferCopy(uint16_t wPMABufAddr, uint16_t offset ,uint16_t wNBytes) { uint32_t n = (wNBytes + 1) >> 1; uint32_t i; uint32_t *pdwVal; pdwVal = (uint32_t *)(wPMABufAddr * 2 + PMAAddr+offset); for (i = n; i != 0; i--) LCD_WRITE_RAM(*pdwVal++); }
void EP1_OUT_Callback(void) { uint16_t dataLen = GetEPRxCount(EP1_OUT & 0x7F); uint16_t offset=0; if(GraphicsState==NOT_ADDRESSED) { if(dataLen<=8) { SetEPRxStatus(ENDP1, EP_RX_VALID); return; } PMAToUserBufferCopy(buffer, GetEPRxAddr(EP1_OUT & 0x7F), 8); uint16_t horz = *((uint16_t*)(buffer)); uint16_t vert = *(uint16_t*)(buffer+2); dataTotal = *(uint32_t*)(buffer+4); LCD_WRITE_REGISTER(CTR_HORZ_ADDRESS,vert); // LCD_WRITE_REGISTER(CTR_VERT_ADDRESS,horz); offset=16; dataTransfered=0x00; GraphicsState=TRANSFER_IN_PROGRESS; dataLen-=8; } LCD_BEGIN_RAM_WRITE; PMAToLCDBufferCopy(GetEPRxAddr(EP1_OUT & 0x7F), offset, dataLen); dataTransfered+=(dataLen)>>1; if(dataTransfered>=dataTotal) GraphicsState=NOT_ADDRESSED; SetEPRxStatus(ENDP1, EP_RX_VALID); }
void (*pEpInt_IN[7])(void) = { NOP_Process, NOP_Process, NOP_Process, NOP_Process, NOP_Process, NOP_Process, NOP_Process, }; void (*pEpInt_OUT[7])(void) = { EP1_OUT_Callback, NOP_Process, NOP_Process, NOP_Process, NOP_Process, NOP_Process, NOP_Process, };
var bytesToWrite = File.ReadAllBytes("D:\\myfile.raw");
Source: https://habr.com/ru/post/163689/
All Articles