Cov txheej txheem:

Poob hauv Stm32: Kev Tswj Chaw Taws Teeb rau Lub Tsev Media Center: 4 Cov Kauj Ruam (nrog Duab)
Poob hauv Stm32: Kev Tswj Chaw Taws Teeb rau Lub Tsev Media Center: 4 Cov Kauj Ruam (nrog Duab)

Video: Poob hauv Stm32: Kev Tswj Chaw Taws Teeb rau Lub Tsev Media Center: 4 Cov Kauj Ruam (nrog Duab)

Video: Poob hauv Stm32: Kev Tswj Chaw Taws Teeb rau Lub Tsev Media Center: 4 Cov Kauj Ruam (nrog Duab)
Video: I Reviewed the Stupidest Smart Devices From My Spam Folder 2024, Hlis ntuj nqeg
Anonim
Poob hauv Stm32: Kev Tswj Chaw Taws Teeb rau Tsev Media Center
Poob hauv Stm32: Kev Tswj Chaw Taws Teeb rau Tsev Media Center

Nov yog qhov ua tiav daim qauv rau tsev xov xwm chaw chaw tswj chaw taws teeb raws li smt32 micro tswj, stm32f103c8t6 hu ua 'bluepill' board. Piv txwv tias, koj tab tom siv PC rau lub chaw tshaj xov xwm hauv tsev. Nws yog qhov kev daws teeb meem yooj yim heev, uas tso cai rau koj tso lub tsev qiv ntawv yees duab loj rau hauv lub hard drive sab hauv, lossis koj tuaj yeem ua yeeb yaj kiab los ntawm lub network, piv txwv li youtube lossis yog li, koj tsis muaj teeb meem nrog codecs lossis video ua si txhua, vim nws yog qhov zoo heev yooj yim los hloov kho software player txhua lub sijhawm. Qhov tsis zoo ntawm qhov kev daws teeb meem no yog tias koj yuav tsum siv nas thiab keyboard los tswj koj txoj kev ua si. IR tswj chaw taws teeb yog hom yooj yim rau qhov no.

Hauv kab lus no kuv yuav qhia yuav ua li cas thiaj tsim tus kheej tswj chaw taws teeb siv chip bluepill board.

Kauj Ruam 1: Lub Tswv Yim

Lub Tswv Yim
Lub Tswv Yim
Lub Tswv Yim
Lub Tswv Yim

Lub tswv yim tseem ceeb yog yooj yim heev: pawg thawj coj saib bluepill tau teeb tsa usb chaw nres nkoj thiab tuaj yeem ua raws li USB HID keyboard. Yog tias peb xa IR tus txais mus rau pawg thawj coj, nws tuaj yeem txhais cov lus txib los ntawm koj li IR tswj chaw taws teeb mus rau 'qhov tseem ceeb nias' ntawm cov keyboard virtual. Tsis tas yuav tsum tau tsav tsheb ntxiv!

Muaj ntau txoj cai IR hauv ntiaj teb ib puag ncig peb. Txhua lub TV ntawm VCS tus muag khoom muaj nws tus kheej IR raws tu qauv. Tab sis tag nrho cov txheej txheem no muaj qee yam tshwm sim: lawv siv mem tes-hloov pauv los ntsuas lub teeb liab. Feem ntau, muaj qee qhov kev npaj ua ntej: kev xav ntev ua ntej thawj zaug hauv pob ntawv. Tom qab ntawd IR tswj xa tag nrho cov pob nrog 0 thiab 1 thiab ua tiav qhov kev xa tawm nrog ua tiav cov mem tes ntev. Txhawm rau txiav txim siab me ntsis peb yuav tsum ntsuas qhov ntsuas qhov ntev thiab qhov ntev ntawm lub ncov. Feem ntau, qhov siab tshaj plaws ntawm logic 0 thiab logic 1 zoo ib yam, qhov sib txawv yog nyob hauv qhov ua tiav mem tes ntev.

Stm32 micro cov tswj hwm tau teeb tsa kom ntes PWM teeb liab. Nyob ze txhua lub sijhawm ntawm tus tswj hwm micro tuaj yeem tso rau hauv 'PWM teeb liab ntes ntau dua' thaum cov channel hloov pauv ntawm tus timer txuag tag nrho qhov ntev ntawm cov mem tes thiab nws qhov siab ntev. Ntawm no kuv yuav tsum hais qhia qhov me me: thaum IR tus txais lub teeb liab, qhov hluav taws xob ntawm nws tus pin ua haujlwm dhau los 0 thiab nyob hauv lub xeev tsis ua haujlwm qhov hluav taws xob hauv tus pin ua haujlwm yog 5 lossis 3.3 volts nyob ntawm IR tus neeg txais khoom siv hluav taws xob. Ie, tus txais 'inverts' lub teeb liab.

Nrog PWM ntes hom stm32 micro tswj tuaj yeem hloov pauv tau yooj yim rau hauv IR chaw taws teeb txhais lus los ntawm IR chaw taws teeb mus rau cov lej keyboard. Tom qab ntawd koj tuaj yeem pib qhov koj nyiam ua software, piv txwv li Kodi ntawm VLC los ua koj cov yeeb yaj kiab uas koj nyiam tshaj plaws ntawm lub chaw tshaj xov xwm.

Kauj Ruam 2: Tsim Tus Tswj

Tsim Tus Tswj
Tsim Tus Tswj
Tsim Tus Tswj
Tsim Tus Tswj
Tsim Tus Tswj
Tsim Tus Tswj
Tsim Tus Tswj
Tsim Tus Tswj

Txhawm rau program stm32 micro maub los kuv xav qhia cov software dawb los ntawm STM: lub kaw lus ua haujlwm (aka ac6) thiab lub rooj teeb tsa lub cuab yeej cubeMX. Txhawm rau rub tawm software mus rau hauv lub micro tswj lub nti clone ntawm ST-Txuas V2 adapter tuaj yeem siv tau. Cov txheej txheem txheej txheem txheej txheem txheej txheem ua haujlwm txuas nrog cov kauj ruam no, cov ntaub ntawv F1-IR_remote.zip.

Lub rooj teeb tsa lub cuab yeej ua kom yooj yim txheej txheem ntawm kev kho vajtse thawj zaug ntawm peb lub micro tswj.

Yog tias koj tab tom siv lub cuab yeej ua haujlwm hauv lub cev, koj tsuas tuaj yeem siv qhov haujlwm rub tawm. Tab sis yog tias koj xav tshuaj xyuas txoj haujlwm kom paub ntau ntxiv, koj tuaj yeem tsim lub rooj teeb tsa teeb tsa hauv cubeMX:

  • Tsim txoj haujlwm tshiab thiab xaiv pawg thawj coj stm32f103c8
  • Xaiv 'Crystal/Ceramic Resonator' rau 'Clock Speed Clock (HSE)' hauv RCC ntawv qhia zaub mov.
  • Xaiv 'Serial Wire' rau cov khoom 'Debug' hauv SYS ntawv qhia zaub mov.
  • Kho lub sijhawm #2 (TIM2 ntawv qhia zaub mov) hauv PWM hom ntes raws li qhia hauv daim duab:

    • Qhev hom -> Pib dua Hom
    • Lub hauv paus chiv keeb -> TI1FP1
    • Clock Source -> Internal Moos
    • Channel1 -> Cov tswv yim ntes hom ncaj qha
  • Teem lub npov 'Ntaus (FS) hauv USB ntawv qhia zaub mov
  • Xaiv 'Human Interface Device Class (HID)' rub-down menu element hauv 'Class of FS IP' yam khoom hauv USB_DEVICE ntawv qhia zaub mov
  • Hauv lub moos teeb tsa vaj huam sib luag, nco ntsoov muab 72 MHz rau lub sijhawm #2 vim tias peb xav tau lub sijhawm suav ntawm txhua 1 mks.
  • Hauv lub vaj huam sib luag teeb tsa teeb tsa USB ntaus ntawv raws li qhia hauv daim duab
  • Hauv vaj huam sib luag teeb tsa teeb tsa timer#2 raws li hauv qab no:

    • Prescaller - 71 (ntawm 0 txog 71) - 1 micro thib zuam!
    • Txee Hom - Saum
    • Lub Sijhawm Teev Npe - 39999 (peb yuav tsum tuaj yeem ntsuas lub plawv dhia ntev)
    • Cov tswv yim ntes channel1 - Ntog Ntog (nco ntsoov tias lub teeb liab los ntawm IR tus txais tau rov qab)

Hauv PWM hom ntes lub timer#2 yuav ua haujlwm hauv qab no:

Thaum lub xub ntiag poob qis pom, lub timer txee yuav raug cawm nyob rau hauv channel1 sau npe thiab lub sijhawm timer yuav rov pib dua nrog 0. Tom qab ntawd lub timer yuav txuas ntxiv suav cov lus qhia. Yog li peb tuaj yeem ntsuas cov mem tes ntev hauv vib nas this yooj yim.

Los ntawm lub neej ntawd STM32 USB HID chav kawm ua piv txwv USB nas. Ntawm no koj tuaj yeem pom cov lus qhia kom tig lub maub los ua cov keyboard.

Kauj Ruam 3: Tailoring Tus Tswj

Txoj haujlwm ua haujlwm nrog Panasonic chaw taws teeb tswj thiab Kodi media center. Txhawm rau txiav txoj haujlwm rau koj tus kheej kev tswj hwm koj yuav tsum ntxiv cov lej kab rau koj cov chaw taws teeb tswj raws li kuv tau ua rau panasonic chaw taws teeb tswj (panasonicCode) mus rau Inc/code.h header. Raws li koj tuaj yeem pom, txhua cov lus txib muaj tus lej tshwj xeeb (hauv IRcommmand enum). Muaj 24 cov lus txib (0-23) lees paub los ntawm txoj haujlwm. Cov lus txib tau txheeb los ntawm qhov muaj feem cuam tshuam.

typedef enum {IR_play = 0, IR_stop, IR_pause, IR_forward, IR_rewind, IR_last_channel, IR_OSD, IR_prevous_menu, IR_left, IR_right, IR_up, IR_enter, IR_chapter_next, IR_chapter_previous, IR_in_tub, IR_th_tub, IR_power, IR_unknown} IRcommand;

const uint16_t kbrd_kodi = {HID_KEY_P, HID_KEY_X, HID_KEY_SPACE, HID_KEY_F, HID_KEY_R, HID_KEY_0, HID_KEY_M, HID_KEY_BACKSPACE, HID_KEY_LEFT, HID_KEY_RIGHT, HID_KEY_UP, HID_KEY_DOWN, HID_KEY_ENTER, HID_KEY_DOT, HID_KEY_COMMA, HID_KEY_S, HID_KEY_I, HID_KEY_T, HID_KEY_L, (uint16_t (HID_LEFT_CTRL) << 8) | HID_KEY_T, HID_KEY_V, HID_KEY_Z, HID_KEY_W, HID_KEY_C};

const uint32_t panasonicCode = {0xd00505d, 0xd00000d, 0xd00606d, 0xd00525f, 0xd00929f, 0x100eced, 0xd00101d, 0x1002b2a, 0x1007273, 0x100f2f3, 0x1005253, 0x100d2d3, 0x1009293, 0x1002c2d, 0x100acad, 0x1009c9d, 0x1008e8f, 0x1004e4f, 0x100cecf, 0x1000e0f, 0x180c041, 0x1801091, 0x180a021, 0xd00bcb1};

Tom qab ntawd koj yuav tsum ntxiv koj tus kheej kev tswj chaw taws teeb hauv qhov pib () txoj hauv kev IR.cpp nrog addRemote () muaj nuj nqi. Cov lus sib cav muaj nuj nqi yog:

  • Tus naj npawb ntawm cov khoom hauv pob ntawv
  • Pob ntawv Header ntev
  • 'Zero' ntsis me ntsis
  • 'Ib' me ntsis ntev
  • Tus taw tes rau tus lej array
  • Cov naj npawb ntawm cov array

void IRcmd:: init (void) {addRemote (48, 5252, 902, 1755, panasonicCode, sizeof (panasonicCode)/sizeof (uint32_t));

}

Tsis tas li cov ntawv muaj lwm lub rooj los hloov cov lus txib rau hauv cov lej keyboard. Kbdr_kodi array muaj cov lej tseem ceeb rau Kodi media center. Koj tuaj yeem ntxiv lwm qhov rau koj tus kheej qhov chaw pabcuam xov xwm, piv txwv li, vlc player. Yog tias koj yuav ntxiv lwm qhov chaw nruab nrab daim ntawv thov rooj, koj yuav tsim lwm yam khoom KBD, thiab pib ua nws hauv main.cpp.

Kauj Ruam 4: Cov cuab yeej los ua kom yooj yim Tailoring

Cov cuab yeej los ua kom yooj yim Tailoring
Cov cuab yeej los ua kom yooj yim Tailoring
Cov cuab yeej los ua kom yooj yim Tailoring
Cov cuab yeej los ua kom yooj yim Tailoring

Muaj ob txoj haujlwm ntxiv hauv cov chaw cia khoom

  • IR tshawb xyuas - tso cai ntsuas lub sijhawm ntsuas ntawm cov cim ntawm koj lub chaw taws teeb.
  • IR_capture - tso cai rau ntes HEX cov lej ntawm koj cov chaw taws teeb tswj.

Tsuas yog thauj IR tshawb xyuas qhov haujlwm thiab txuas USB chaw nres nkoj ntawm bluepill board rau hauv koj lub computer. Tom qab ntawd tso tawm ib qho kev pabcuam davhlau ya nyob twg ntawm lub tshuab ntaus ntawv chaw nres nkoj virtual, sib thooj rau pawg thawj coj stm32. Thaum koj nias cov nyees khawm ntawm koj cov chaw taws teeb, txoj haujlwm yuav ntsuas cov mem tes tau txais thiab luam tawm lub sijhawm nruab nrab rau cov mem tes sib txawv. Nws yuav tsum ua kom yooj yim txhawm rau txheeb xyuas lub plawv dhia ntev rau pob ntawv pob, xoom thiab ib qho me me.

Hauv IR txoj haujlwm tshawb nrhiav lub sijhawm #2 tab tom ua haujlwm hauv PWM hom kev ntes nrog ob txoj hauv kev: channel ib qho tau txais tag nrho cov mem tes ntev thiab channel2 ntes lub sijhawm ntev. Thaum pom lub teeb liab poob qis pom, tus nqi lub sijhawm tau txais kev cawmdim rau hauv cov channel ib tus rau npe thiab lub sijhawm rov pib dua nrog 0. Thaum lub ntug nce ntawm lub teeb liab pom, lub sijhawm timer tau txais kev cawmdim rau hauv channel 2 register.

Txhawm rau ntes cov lej khawm ntawm koj tus kheej kev tswj chaw taws teeb, IR_capture project tuaj yeem siv. Hauv cov ntaub ntawv main.c koj yuav tsum ntxiv cov lus txhais nyob deb xws li qhov no:

IRcode panasonic = {.hdr = 5252,.bits = 48,.zero = 902,.one = 1755,.dev = 60};

  • .hdr - lub taub hau ntev hauv mks
  • .bits - tus naj npawb ntawm cov khoom hauv pob ntawv
  • .zero - qhov ntev ntawm xoom me ntsis
  • .one - qhov ntev ib qho me ntsis
  • .dev - qhov sib txawv (qhov sib txawv ntawm lub sijhawm uas tuaj yeem lees txais). Feem ntau nws yog 1/10 ntawm qhov tsawg tshaj plaws ntev.

Tom qab ntawd ntxiv koj cov chaw taws teeb rau hauv cov npe ntawm kev txhawb nqa kev txhawb nqa:

const IRcode* chaw taws teeb [2] = {& panasonic, & pioneer};

Pom zoo: