0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

(レジ直出力)ESP32でナイトライダーを考える。(実機で動くかは、不明)

Last updated at Posted at 2023-10-04

x つねに進化するので過去のことは、わすれてね!!

目的
カラー液晶の転送高速化に必要
ESP32は、セットとリセットのレジスターが別とで
1を立てるとセットまたは、リセットされる。
オンラインコンパイラーを使いアルゴリズムのチェックをする

いろいろ
いろいろ釣り針を仕掛けているが
今日は、なぜか大漁。
ひさしぶりの大漁
大漁旗をだせーーーー
それー、それー、お祭りだー

プログラムネタでカウンターが上がる条件は、

●ちょっと難しい。
●かんたんにする。
●やくにたつ。

しらず、しらずに自分が天才になつた快感に浸れるらしい。

レジスターの仮の名前

A_SET
A_RESET

B_SET
B_RESET


プログラムの構成

  1. 8ビットをワークAレジとワークBレジ(33ポートのみ)に分けて転記する

IN_8BIT

WORK_A
WORK_B

WORK_A と WORK_Bの初期化

●レジBの処理

8回繰り返し

if( IN_8BIT アンド (ビットマスク) = 1 {

WORK_A = WORK_A | (1<<x)

}

繰り返しおわり

●レジBの処理

if( IN_8BIT アンド (ビットマスク) = 1 {

WORK_B = WORK_B | (1<<x)

}

2.ワークAレジをセットレジとリセットレジに分けてアウト

●セットレジ

SET_REG = SET_REG | (ビットマスク) とりあえず関係ビットをクリア

SET_REG = (ビットマスク) アンド WORK_A

●リセットレジ

RESET_REG = RESET_REG | (ビットマスク) とりあえず関係ビットをクリア

WORK_A = 反転(WORK_A)

RESET_REG = (ビットマスク) アンド WORK_A

OUT_ = RESET_REG

3.ワークBレジをセットレジとリセットレジに分けてアウト

if( WORK_B アンド (ビットマスク) = 1 )
{

OUT_ = OUT_ オア (1<<x) 設定

OUT_ = OUT_ アンド 反転(1<<x) 非設定

} else {

OUT_ = OUT_ アンド 反転(1<<x) 非設定

OUT_ = OUT_ オア (1<<x) 設定

}

  1. メイン処理

8ビットシフターによる処理

for i=0 to 7

8ビット出力関数( (i << x) )

next


プログラム

8ビットをワークAレジとワークBレジ(33ポートのみ)に分けて転記する
ワークAレジをセットレジとリセットレジに分けてアウト

こんな感じ


#include <iostream>
using namespace std;


//#define GPIO_0to31SET_REG   *((volatile unsigned long *)GPIO_OUT_W1TS_REG)
//#define GPIO_0to31CLR_REG   *((volatile unsigned long *)GPIO_OUT_W1TC_REG)


unsigned long GPIO_0to31SET_REG = 0;
unsigned long GPIO_0to31CLR_REG = 0;



//#define GPIO_DB7  14
//#define GPIO_DB6  4
//#define GPIO_DB5  27
//#define GPIO_DB4  16
//#define GPIO_DB3  26
//#define GPIO_DB2  17
//#define GPIO_DB1  25
//#define GPIO_DB0  5


void GPIO_8BIT(uint8_t s)
{
  
  int work_a = 0;

  //7bit

  work_a = work_a | ( (s >> 7) & 1) << 14 ;

  //6bit

  work_a = work_a | ( (s >> 6) & 1) << 4;

  //5bit

  work_a = work_a | ( (s >> 5) & 1) << 27;

  //4bit


  work_a = work_a | ( (s >> 4) & 1) << 16;

  //3bit

  work_a = work_a | ( (s >> 3) & 1) << 26;

  //2bit

  work_a = work_a | ( (s >> 2) & 1) << 17;


  //1bit

  work_a = work_a | ( (s >> 1) & 1) << 25;


  //0bit

  work_a = work_a | ( s & 1) << 5;


  //[0-31]レジスターの書き込み
  //out_a_xxx(work_a);


  //セットレジスターの設定
  GPIO_0to31SET_REG = GPIO_0to31SET_REG | work_a;


  //リセットレジスターの設定 反転させてマスクして足しこむ
  GPIO_0to31CLR_REG = GPIO_0to31CLR_REG |

(

(  (1 << 14)|(1 << 4)|(1 << 27)|(1 << 16) | (1 << 26)|(1 << 17)|(1 << 25)|(1 << 5)  )

 & (~work_a)

);



} //GPIO_8BIT


void bit_o(int rrr_a)
{



    printf("333222222222211111111110000000000\r\n");
    printf("210987654321098765432109876543210\r\n"); 
    printf("     ***       ** *        **    \r\n"); 

    printf("00000");
    
    for(int i = 0;i<(27+1);i++){
        
        //printf("%d:%d\r\n",i,(27-i));
        
        printf("%d",  (rrr_a & (   1<<(27-i)  )) >> (27-i)   );
        
    }//for
    
    printf("\r\n");

} //bit

int main(void){
    

    // Your code here!
    printf("START\r\n");


    GPIO_8BIT( 1<<5);

    bit_o(GPIO_0to31SET_REG);
    //bit_o(GPIO_0to31CLR_REG);

}



結果


START
333222222222211111111110000000000
210987654321098765432109876543210
     ***       ** *        **    
000001000000000000000000000000000


GPIOの低レベルアクセス
約2倍程度になるらしい。
どっかのサイト

o_cop651.jpg

参考した(適当にぱくった)



#define GPIO_0to31SET_REG   *((volatile unsigned long *)GPIO_OUT_W1TS_REG)
#define GPIO_0to31CLR_REG   *((volatile unsigned long *)GPIO_OUT_W1TC_REG)

#define pin3 5

GPIO_0to31SET_REG = 1<<pin3;
GPIO_0to31CLR_REG = 1<<pin3;






0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?