Translate code comment

This commit is contained in:
izilzty
2022-07-07 09:49:08 +08:00
parent f779cc0a28
commit 307bcfc2e9
2 changed files with 37 additions and 51 deletions
+18 -25
View File
@@ -31,15 +31,8 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
U8g2的SPI统一使用MSB顺序,而此屏幕需要LSB顺序,按照U8g2的逻辑,使用SWAP8()交换命令字节顺序,使用u8g2_ll_hvline_vertical_top_msb()交换显示数据字节顺序。
注意:此版本不能支持U8x8,因为U8x8是直接向屏幕写入数据的,没有机会来交换字节顺序,如果需要使用U8x8只能使用上一版本。
上一版本中使用了i2c速度作为标志来修改Arduino的SPI字节发送顺序,所以支持U8x8,但如果使用软件模拟SPI时则会出现问题。
如使用非Arduino控制器,在自行初始化SPI时应统一初始化为:active lowfalling edgeMSB (CPOL=1 CPHA=1 MSB) 即可,不要按照屏幕数据表初始化为LSB。
Arduino在使用3W_SPI时U8g2会自动多发一个DC位,将导致数据错位,所以在发送数据时应使用4W_SPI,并忽略DC引脚即可。其他控制器如果调用了u8x8_byte_3wire_sw_spi()也会出现此问题,改为调用u8x8_byte_4wire_sw_spi()即可。
*/
#include "u8x8.h"
#define SWAP8(a) ((((a)&0x80) >> 7) | (((a)&0x40) >> 5) | (((a)&0x20) >> 3) | (((a)&0x10) >> 1) | (((a)&0x08) << 1) | (((a)&0x04) << 3) | (((a)&0x02) << 5) | (((a)&0x01) << 7))
@@ -60,18 +53,18 @@ static const u8x8_display_info_t u8x8_gp1247ai_display_info = {
/* i2c_bus_clock_100kHz = */ 4, /* */
/* data_setup_time_ns = */ 60, /* tsu */
/* write_pulse_width_ns = */ 120, /* tcyc/2 */
/* tile_width = */ 32, /* 32*8=256 内存像素 */
/* tile_hight = */ 8, /* 8*8=64 内存像素 */
/* tile_width = */ 32, /* 32*8=256 memory size */
/* tile_hight = */ 8, /* 8*8=64 memory size */
/* default_x_offset = */ 0, /* */
/* flipmode_x_offset = */ 0, /* */
/* pixel_width = */ 253, /* 屏幕实际像素 */
/* pixel_height = */ 63 /* 屏幕实际像素 */
/* pixel_width = */ 253, /* display size */
/* pixel_height = */ 63 /* display size */
};
static const uint8_t u8x8_d_gp1247ai_init_seq[] = {
U8X8_START_TRANSFER(),
U8X8_C(SWAP8(0x0AA)), /* Software reset */
U8X8_END_TRANSFER(),
U8X8_DLY(1), /* 等待复位完成 */
U8X8_DLY(1), /* Wait for reset */
U8X8_START_TRANSFER(),
U8X8_CA(SWAP8(0x078), SWAP8(0x008)), /* Oscillation Setting */
@@ -91,13 +84,13 @@ static const uint8_t u8x8_d_gp1247ai_init_seq[] = {
U8X8_END_TRANSFER(),
U8X8_START_TRANSFER(),
U8X8_CAA(SWAP8(0x0A0), SWAP8(0x000), SWAP8(0x028)), /* Dimming level Setting 1024级亮度设置,车机夜间(ILL线接12V)0x00,0x66,普通模式(ILL线接不接)为最大0x03,0xFF */
U8X8_CAA(SWAP8(0x0A0), SWAP8(0x000), SWAP8(0x028)), /* Dimming level Setting (1024 level, 0x3FF max) */
U8X8_END_TRANSFER(),
U8X8_START_TRANSFER(),
U8X8_C(SWAP8(0x055)), /* Memory Map Clear */
U8X8_END_TRANSFER(),
U8X8_DLY(15), /* 等待内存清零 */
U8X8_DLY(15), /* Wait for memory clear */
U8X8_START_TRANSFER(),
U8X8_CAA(SWAP8(0x0C0), SWAP8(0x000), SWAP8(0x000)), /* DW1 position setting */
@@ -112,7 +105,7 @@ static const uint8_t u8x8_d_gp1247ai_init_seq[] = {
U8X8_END_TRANSFER(),
U8X8_START_TRANSFER(),
U8X8_C(SWAP8(0x061)), /* Standby */
U8X8_C(SWAP8(0x061)), /* Standby Mode */
U8X8_END_TRANSFER(),
U8X8_END() /* end of sequence */
@@ -128,10 +121,10 @@ static const uint8_t u8x8_d_gp1247ai_wakeup_seq[] = {
U8X8_START_TRANSFER(),
U8X8_C(SWAP8(0x06D)), /* Wake up */
U8X8_END_TRANSFER(),
U8X8_DLY(1), /* 等待震荡器稳定 */
U8X8_DLY(1), /* Wait for OSC stabilize */
U8X8_START_TRANSFER(),
U8X8_CA(SWAP8(0x080), SWAP8(0x080)), /* 进入Standby后显示模式设置SC位会被自动清零,重新设置 */
U8X8_CA(SWAP8(0x080), SWAP8(0x080)), /* After entering standby mode, the SC bit will be automatically cleared */
U8X8_END_TRANSFER(),
U8X8_END() /* end of sequence */
@@ -154,23 +147,23 @@ uint8_t u8x8_d_gp1247ai_common(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void
case U8X8_MSG_DISPLAY_SET_CONTRAST:
u8x8_cad_StartTransfer(u8x8);
u8x8_cad_SendCmd(u8x8, SWAP8(0x0A0));
u8x8_cad_SendArg(u8x8, SWAP8((arg_int * 4) >> 8)); /* 亮度高位(屏幕支持0~1023,U8g2输入只有0~255,平均分配) */
u8x8_cad_SendArg(u8x8, SWAP8((arg_int * 4) & 0xFF)); /* 亮度低位(屏幕支持0~1023,U8g2输入只有0~255,平均分配) */
u8x8_cad_SendArg(u8x8, SWAP8((arg_int * 4) >> 8)); /* Dimming level */
u8x8_cad_SendArg(u8x8, SWAP8((arg_int * 4) & 0xFF)); /* Dimming level */
u8x8_cad_EndTransfer(u8x8);
break;
#endif
case U8X8_MSG_DISPLAY_DRAW_TILE:
ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr; /* 要发送数据的指针 */
x = ((u8x8_tile_t *)arg_ptr)->x_pos * 8; /* 起始X位置,U8g2始终为0,仅U8x8使用 */
y = ((u8x8_tile_t *)arg_ptr)->y_pos * 8; /* 起始Y位置 */
tx_cnt = ((u8x8_tile_t *)arg_ptr)->cnt * 8; /* 一次发送的数据尺寸 U8g2:(32 * 8 = 256)、U8x8:(1 * 8 = 8 */
ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
x = ((u8x8_tile_t *)arg_ptr)->x_pos * 8;
y = ((u8x8_tile_t *)arg_ptr)->y_pos * 8;
tx_cnt = ((u8x8_tile_t *)arg_ptr)->cnt * 8;
u8x8_cad_StartTransfer(u8x8);
u8x8_cad_SendCmd(u8x8, SWAP8(0x0F0));
u8x8_cad_SendArg(u8x8, SWAP8(x));
u8x8_cad_SendArg(u8x8, SWAP8(y));
u8x8_cad_SendArg(u8x8, SWAP8(0x007)); /* Y方向每8像素自动折返 */
u8x8_cad_SendArg(u8x8, SWAP8(0x007)); /* return every 8 pixels */
do
{
while (tx_cnt > 0)
+19 -26
View File
@@ -31,15 +31,8 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
U8g2的SPI统一使用MSB顺序,而此屏幕需要LSB顺序,按照U8g2的逻辑,使用SWAP8()交换命令字节顺序,使用u8g2_ll_hvline_vertical_top_msb()交换显示数据字节顺序。
注意:此版本不能支持U8x8,因为U8x8是直接向屏幕写入数据的,没有机会来交换字节顺序,如果需要使用U8x8只能使用上一版本。
上一版本中使用了i2c速度作为标志来修改Arduino的SPI字节发送顺序,所以支持U8x8,但如果使用软件模拟SPI时则会出现问题。
如使用非Arduino控制器,在自行初始化SPI时应统一初始化为:active lowfalling edgeMSB (CPOL=1 CPHA=1 MSB) 即可,不要按照屏幕数据表初始化为LSB。
Arduino在使用3W_SPI时U8g2会自动多发一个DC位,将导致数据错位,所以在发送数据时应使用4W_SPI,并忽略DC引脚即可。其他控制器如果调用了u8x8_byte_3wire_sw_spi()也会出现此问题,改为调用u8x8_byte_4wire_sw_spi()即可。
*/
#include "u8x8.h"
#define SWAP8(a) ((((a)&0x80) >> 7) | (((a)&0x40) >> 5) | (((a)&0x20) >> 3) | (((a)&0x10) >> 1) | (((a)&0x08) << 1) | (((a)&0x04) << 3) | (((a)&0x02) << 5) | (((a)&0x01) << 7))
@@ -60,18 +53,18 @@ static const u8x8_display_info_t u8x8_gp1287ai_display_info = {
/* i2c_bus_clock_100kHz = */ 4, /* */
/* data_setup_time_ns = */ 60, /* tsu */
/* write_pulse_width_ns = */ 120, /* tcyc/2 */
/* tile_width = */ 32, /* 32*8=256 内存像素 */
/* tile_hight = */ 7, /* 7*8=56 内存像素 */
/* tile_width = */ 32, /* 32*8=256 memory size */
/* tile_hight = */ 7, /* 7*8=56 memory size */
/* default_x_offset = */ 0, /* */
/* flipmode_x_offset = */ 0, /* */
/* pixel_width = */ 256, /* 屏幕实际像素 */
/* pixel_height = */ 50 /* 屏幕实际像素 */
/* pixel_width = */ 256, /* display size */
/* pixel_height = */ 50 /* display size */
};
static const uint8_t u8x8_d_gp1287ai_init_seq[] = {
U8X8_START_TRANSFER(),
U8X8_C(SWAP8(0x0AA)), /* Software reset */
U8X8_END_TRANSFER(),
U8X8_DLY(1), /* 等待复位完成 */
U8X8_DLY(1), /* Wait for reset */
U8X8_START_TRANSFER(),
U8X8_CA(SWAP8(0x078), SWAP8(0x008)), /* Oscillation Setting */
@@ -91,13 +84,13 @@ static const uint8_t u8x8_d_gp1287ai_init_seq[] = {
U8X8_END_TRANSFER(),
U8X8_START_TRANSFER(),
U8X8_CAA(SWAP8(0x0A0), SWAP8(0x000), SWAP8(0x028)), /* Dimming level Setting 1024级亮度设置,车机夜间(ILL线接12V)0x00,0x66,普通模式(ILL线接不接)为最大0x03,0xFF */
U8X8_CAA(SWAP8(0x0A0), SWAP8(0x000), SWAP8(0x028)), /* Dimming level Setting (1024 level, 0x3FF max) */
U8X8_END_TRANSFER(),
U8X8_START_TRANSFER(),
U8X8_C(SWAP8(0x055)), /* Memory Map Clear */
U8X8_END_TRANSFER(),
U8X8_DLY(15), /* 等待内存清零 */
U8X8_DLY(15), /* Waiting for memory clear */
U8X8_START_TRANSFER(),
U8X8_CAA(SWAP8(0x0C0), SWAP8(0x000), SWAP8(0x004)), /* DW1 position setting */
@@ -108,7 +101,7 @@ static const uint8_t u8x8_d_gp1287ai_init_seq[] = {
U8X8_END_TRANSFER(),
U8X8_START_TRANSFER(),
U8X8_CA(SWAP8(0x090), SWAP8(0x000)), /* 未知命令 */
U8X8_CA(SWAP8(0x090), SWAP8(0x000)), /* Internal Command */
U8X8_END_TRANSFER(),
U8X8_START_TRANSFER(),
@@ -120,7 +113,7 @@ static const uint8_t u8x8_d_gp1287ai_init_seq[] = {
U8X8_END_TRANSFER(),
U8X8_START_TRANSFER(),
U8X8_C(SWAP8(0x061)), /* Standby */
U8X8_C(SWAP8(0x061)), /* Standby Mode */
U8X8_END_TRANSFER(),
U8X8_END() /* end of sequence */
@@ -136,10 +129,10 @@ static const uint8_t u8x8_d_gp1287ai_wakeup_seq[] = {
U8X8_START_TRANSFER(),
U8X8_C(SWAP8(0x06D)), /* Wake up */
U8X8_END_TRANSFER(),
U8X8_DLY(1), /* 等待震荡器稳定 */
U8X8_DLY(1), /* Wait for OSC stabilize */
U8X8_START_TRANSFER(),
U8X8_CA(SWAP8(0x080), SWAP8(0x000)), /* 进入Standby后显示模式设置SC位会被自动清零,重新设置 */
U8X8_CA(SWAP8(0x080), SWAP8(0x000)), /* After entering standby mode, the SC bit will be automatically cleared */
U8X8_END_TRANSFER(),
U8X8_END() /* end of sequence */
@@ -162,23 +155,23 @@ uint8_t u8x8_d_gp1287ai_common(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void
case U8X8_MSG_DISPLAY_SET_CONTRAST:
u8x8_cad_StartTransfer(u8x8);
u8x8_cad_SendCmd(u8x8, SWAP8(0x0A0));
u8x8_cad_SendArg(u8x8, SWAP8((arg_int * 4) >> 8)); /* 亮度高位(屏幕支持0~1023,U8g2输入只有0~255,平均分配) */
u8x8_cad_SendArg(u8x8, SWAP8((arg_int * 4) & 0xFF)); /* 亮度低位(屏幕支持0~1023,U8g2输入只有0~255,平均分配) */
u8x8_cad_SendArg(u8x8, SWAP8((arg_int * 4) >> 8)); /* Dimming level */
u8x8_cad_SendArg(u8x8, SWAP8((arg_int * 4) & 0xFF)); /* Dimming level */
u8x8_cad_EndTransfer(u8x8);
break;
#endif
case U8X8_MSG_DISPLAY_DRAW_TILE:
ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr; /* 要发送数据的指针 */
x = ((u8x8_tile_t *)arg_ptr)->x_pos * 8; /* 起始X位置,U8g2始终为0,仅U8x8使用 */
y = ((u8x8_tile_t *)arg_ptr)->y_pos * 8 + 4; /* 起始Y位置,要加上屏幕本身的偏移 */
tx_cnt = ((u8x8_tile_t *)arg_ptr)->cnt * 8; /* 一次发送的数据尺寸 U8g2:(32 * 8 = 256)、U8x8:(1 * 8 = 8 */
ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
x = ((u8x8_tile_t *)arg_ptr)->x_pos * 8;
y = ((u8x8_tile_t *)arg_ptr)->y_pos * 8 + 4;
tx_cnt = ((u8x8_tile_t *)arg_ptr)->cnt * 8;
u8x8_cad_StartTransfer(u8x8);
u8x8_cad_SendCmd(u8x8, SWAP8(0x0F0));
u8x8_cad_SendArg(u8x8, SWAP8(x));
u8x8_cad_SendArg(u8x8, SWAP8(y));
u8x8_cad_SendArg(u8x8, SWAP8(0x007)); /* Y方向每8像素自动折返 */
u8x8_cad_SendArg(u8x8, SWAP8(0x007)); /* return every 8 pixels */
do
{
while (tx_cnt > 0)