lsm6ds3tr-c_reg.c 215 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219
  1. /**
  2. ******************************************************************************
  3. * @file lsm6ds3tr_c_reg.c
  4. * @author Sensors Software Solution Team
  5. * @brief LSM6DS3TR_C driver file
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. #include "lsm6ds3tr-c_reg.h"
  20. /**
  21. * @defgroup LSM6DS3TR_C
  22. * @brief This file provides a set of functions needed to drive the
  23. * lsm6ds3tr_c enanced inertial module.
  24. * @{
  25. *
  26. */
  27. /**
  28. * @defgroup LSM6DS3TR_C_interfaces_functions
  29. * @brief This section provide a set of functions used to read and
  30. * write a generic register of the device.
  31. * MANDATORY: return 0 -> no Error.
  32. * @{
  33. *
  34. */
  35. /**
  36. * @brief Read generic device register
  37. *
  38. * @param ctx read / write interface definitions(ptr)
  39. * @param reg register to read
  40. * @param data pointer to buffer that store the data read(ptr)
  41. * @param len number of consecutive register to read
  42. * @retval interface status (MANDATORY: return 0 -> no Error)
  43. *
  44. */
  45. int32_t __weak lsm6ds3tr_c_read_reg(const stmdev_ctx_t *ctx, uint8_t reg,
  46. uint8_t *data,
  47. uint16_t len)
  48. {
  49. int32_t ret;
  50. if (ctx == NULL)
  51. {
  52. return -1;
  53. }
  54. ret = ctx->read_reg(ctx->handle, reg, data, len);
  55. return ret;
  56. }
  57. /**
  58. * @brief Write generic device register
  59. *
  60. * @param ctx read / write interface definitions(ptr)
  61. * @param reg register to write
  62. * @param data pointer to data to write in register reg(ptr)
  63. * @param len number of consecutive register to write
  64. * @retval interface status (MANDATORY: return 0 -> no Error)
  65. *
  66. */
  67. int32_t __weak lsm6ds3tr_c_write_reg(const stmdev_ctx_t *ctx, uint8_t reg,
  68. uint8_t *data,
  69. uint16_t len)
  70. {
  71. int32_t ret;
  72. if (ctx == NULL)
  73. {
  74. return -1;
  75. }
  76. ret = ctx->write_reg(ctx->handle, reg, data, len);
  77. return ret;
  78. }
  79. /**
  80. * @}
  81. *
  82. */
  83. /**
  84. * @defgroup LSM6DS3TR_C_Sensitivity
  85. * @brief These functions convert raw-data into engineering units.
  86. * @{
  87. *
  88. */
  89. float_t lsm6ds3tr_c_from_fs2g_to_mg(int16_t lsb)
  90. {
  91. return ((float_t)lsb * 0.061f);
  92. }
  93. float_t lsm6ds3tr_c_from_fs4g_to_mg(int16_t lsb)
  94. {
  95. return ((float_t)lsb * 0.122f);
  96. }
  97. float_t lsm6ds3tr_c_from_fs8g_to_mg(int16_t lsb)
  98. {
  99. return ((float_t)lsb * 0.244f);
  100. }
  101. float_t lsm6ds3tr_c_from_fs16g_to_mg(int16_t lsb)
  102. {
  103. return ((float_t)lsb * 0.488f);
  104. }
  105. float_t lsm6ds3tr_c_from_fs125dps_to_mdps(int16_t lsb)
  106. {
  107. return ((float_t)lsb * 4.375f);
  108. }
  109. float_t lsm6ds3tr_c_from_fs250dps_to_mdps(int16_t lsb)
  110. {
  111. return ((float_t)lsb * 8.750f);
  112. }
  113. float_t lsm6ds3tr_c_from_fs500dps_to_mdps(int16_t lsb)
  114. {
  115. return ((float_t)lsb * 17.50f);
  116. }
  117. float_t lsm6ds3tr_c_from_fs1000dps_to_mdps(int16_t lsb)
  118. {
  119. return ((float_t)lsb * 35.0f);
  120. }
  121. float_t lsm6ds3tr_c_from_fs2000dps_to_mdps(int16_t lsb)
  122. {
  123. return ((float_t)lsb * 70.0f);
  124. }
  125. float_t lsm6ds3tr_c_from_lsb_to_celsius(int16_t lsb)
  126. {
  127. return (((float_t)lsb / 256.0f) + 25.0f);
  128. }
  129. /**
  130. * @}
  131. *
  132. */
  133. /**
  134. * @defgroup LSM6DS3TR_C_data_generation
  135. * @brief This section groups all the functions concerning data
  136. * generation
  137. * @{
  138. *
  139. */
  140. /**
  141. * @brief Accelerometer full-scale selection.[set]
  142. *
  143. * @param ctx Read / write interface definitions
  144. * @param val Change the values of fs_xl in reg CTRL1_XL
  145. * @retval Interface status (MANDATORY: return 0 -> no Error).
  146. *
  147. */
  148. int32_t lsm6ds3tr_c_xl_full_scale_set(const stmdev_ctx_t *ctx,
  149. lsm6ds3tr_c_fs_xl_t val)
  150. {
  151. lsm6ds3tr_c_ctrl1_xl_t ctrl1_xl;
  152. int32_t ret;
  153. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  154. (uint8_t *)&ctrl1_xl, 1);
  155. if (ret == 0)
  156. {
  157. ctrl1_xl.fs_xl = (uint8_t) val;
  158. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  159. (uint8_t *)&ctrl1_xl, 1);
  160. }
  161. return ret;
  162. }
  163. /**
  164. * @brief Accelerometer full-scale selection.[get]
  165. *
  166. * @param ctx Read / write interface definitions
  167. * @param val Get the values of fs_xl in reg CTRL1_XL
  168. * @retval Interface status (MANDATORY: return 0 -> no Error).
  169. *
  170. */
  171. int32_t lsm6ds3tr_c_xl_full_scale_get(const stmdev_ctx_t *ctx,
  172. lsm6ds3tr_c_fs_xl_t *val)
  173. {
  174. lsm6ds3tr_c_ctrl1_xl_t ctrl1_xl;
  175. int32_t ret;
  176. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  177. (uint8_t *)&ctrl1_xl, 1);
  178. switch (ctrl1_xl.fs_xl)
  179. {
  180. case LSM6DS3TR_C_2g:
  181. *val = LSM6DS3TR_C_2g;
  182. break;
  183. case LSM6DS3TR_C_16g:
  184. *val = LSM6DS3TR_C_16g;
  185. break;
  186. case LSM6DS3TR_C_4g:
  187. *val = LSM6DS3TR_C_4g;
  188. break;
  189. case LSM6DS3TR_C_8g:
  190. *val = LSM6DS3TR_C_8g;
  191. break;
  192. default:
  193. *val = LSM6DS3TR_C_XL_FS_ND;
  194. break;
  195. }
  196. return ret;
  197. }
  198. /**
  199. * @brief Accelerometer data rate selection.[set]
  200. *
  201. * @param ctx Read / write interface definitions
  202. * @param val Change the values of odr_xl in reg CTRL1_XL
  203. * @retval Interface status (MANDATORY: return 0 -> no Error).
  204. *
  205. */
  206. int32_t lsm6ds3tr_c_xl_data_rate_set(const stmdev_ctx_t *ctx,
  207. lsm6ds3tr_c_odr_xl_t val)
  208. {
  209. lsm6ds3tr_c_ctrl1_xl_t ctrl1_xl;
  210. int32_t ret;
  211. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  212. (uint8_t *)&ctrl1_xl, 1);
  213. if (ret == 0)
  214. {
  215. ctrl1_xl.odr_xl = (uint8_t) val;
  216. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  217. (uint8_t *)&ctrl1_xl, 1);
  218. }
  219. return ret;
  220. }
  221. /**
  222. * @brief Accelerometer data rate selection.[get]
  223. *
  224. * @param ctx Read / write interface definitions
  225. * @param val Get the values of odr_xl in reg CTRL1_XL
  226. * @retval Interface status (MANDATORY: return 0 -> no Error).
  227. *
  228. */
  229. int32_t lsm6ds3tr_c_xl_data_rate_get(const stmdev_ctx_t *ctx,
  230. lsm6ds3tr_c_odr_xl_t *val)
  231. {
  232. lsm6ds3tr_c_ctrl1_xl_t ctrl1_xl;
  233. int32_t ret;
  234. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  235. (uint8_t *)&ctrl1_xl, 1);
  236. switch (ctrl1_xl.odr_xl)
  237. {
  238. case LSM6DS3TR_C_XL_ODR_OFF:
  239. *val = LSM6DS3TR_C_XL_ODR_OFF;
  240. break;
  241. case LSM6DS3TR_C_XL_ODR_12Hz5:
  242. *val = LSM6DS3TR_C_XL_ODR_12Hz5;
  243. break;
  244. case LSM6DS3TR_C_XL_ODR_26Hz:
  245. *val = LSM6DS3TR_C_XL_ODR_26Hz;
  246. break;
  247. case LSM6DS3TR_C_XL_ODR_52Hz:
  248. *val = LSM6DS3TR_C_XL_ODR_52Hz;
  249. break;
  250. case LSM6DS3TR_C_XL_ODR_104Hz:
  251. *val = LSM6DS3TR_C_XL_ODR_104Hz;
  252. break;
  253. case LSM6DS3TR_C_XL_ODR_208Hz:
  254. *val = LSM6DS3TR_C_XL_ODR_208Hz;
  255. break;
  256. case LSM6DS3TR_C_XL_ODR_416Hz:
  257. *val = LSM6DS3TR_C_XL_ODR_416Hz;
  258. break;
  259. case LSM6DS3TR_C_XL_ODR_833Hz:
  260. *val = LSM6DS3TR_C_XL_ODR_833Hz;
  261. break;
  262. case LSM6DS3TR_C_XL_ODR_1k66Hz:
  263. *val = LSM6DS3TR_C_XL_ODR_1k66Hz;
  264. break;
  265. case LSM6DS3TR_C_XL_ODR_3k33Hz:
  266. *val = LSM6DS3TR_C_XL_ODR_3k33Hz;
  267. break;
  268. case LSM6DS3TR_C_XL_ODR_6k66Hz:
  269. *val = LSM6DS3TR_C_XL_ODR_6k66Hz;
  270. break;
  271. case LSM6DS3TR_C_XL_ODR_1Hz6:
  272. *val = LSM6DS3TR_C_XL_ODR_1Hz6;
  273. break;
  274. default:
  275. *val = LSM6DS3TR_C_XL_ODR_ND;
  276. break;
  277. }
  278. return ret;
  279. }
  280. /**
  281. * @brief Gyroscope chain full-scale selection.[set]
  282. *
  283. * @param ctx Read / write interface definitions
  284. * @param val Change the values of fs_g in reg CTRL2_G
  285. * @retval Interface status (MANDATORY: return 0 -> no Error).
  286. *
  287. */
  288. int32_t lsm6ds3tr_c_gy_full_scale_set(const stmdev_ctx_t *ctx,
  289. lsm6ds3tr_c_fs_g_t val)
  290. {
  291. lsm6ds3tr_c_ctrl2_g_t ctrl2_g;
  292. int32_t ret;
  293. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL2_G,
  294. (uint8_t *)&ctrl2_g, 1);
  295. if (ret == 0)
  296. {
  297. ctrl2_g.fs_g = (uint8_t) val;
  298. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL2_G,
  299. (uint8_t *)&ctrl2_g, 1);
  300. }
  301. return ret;
  302. }
  303. /**
  304. * @brief Gyroscope chain full-scale selection.[get]
  305. *
  306. * @param ctx Read / write interface definitions
  307. * @param val Get the values of fs_g in reg CTRL2_G
  308. * @retval Interface status (MANDATORY: return 0 -> no Error).
  309. *
  310. */
  311. int32_t lsm6ds3tr_c_gy_full_scale_get(const stmdev_ctx_t *ctx,
  312. lsm6ds3tr_c_fs_g_t *val)
  313. {
  314. lsm6ds3tr_c_ctrl2_g_t ctrl2_g;
  315. int32_t ret;
  316. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL2_G,
  317. (uint8_t *)&ctrl2_g, 1);
  318. switch (ctrl2_g.fs_g)
  319. {
  320. case LSM6DS3TR_C_250dps:
  321. *val = LSM6DS3TR_C_250dps;
  322. break;
  323. case LSM6DS3TR_C_125dps:
  324. *val = LSM6DS3TR_C_125dps;
  325. break;
  326. case LSM6DS3TR_C_500dps:
  327. *val = LSM6DS3TR_C_500dps;
  328. break;
  329. case LSM6DS3TR_C_1000dps:
  330. *val = LSM6DS3TR_C_1000dps;
  331. break;
  332. case LSM6DS3TR_C_2000dps:
  333. *val = LSM6DS3TR_C_2000dps;
  334. break;
  335. default:
  336. *val = LSM6DS3TR_C_GY_FS_ND;
  337. break;
  338. }
  339. return ret;
  340. }
  341. /**
  342. * @brief Gyroscope data rate selection.[set]
  343. *
  344. * @param ctx Read / write interface definitions
  345. * @param val Change the values of odr_g in reg CTRL2_G
  346. * @retval Interface status (MANDATORY: return 0 -> no Error).
  347. *
  348. */
  349. int32_t lsm6ds3tr_c_gy_data_rate_set(const stmdev_ctx_t *ctx,
  350. lsm6ds3tr_c_odr_g_t val)
  351. {
  352. lsm6ds3tr_c_ctrl2_g_t ctrl2_g;
  353. int32_t ret;
  354. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL2_G,
  355. (uint8_t *)&ctrl2_g, 1);
  356. if (ret == 0)
  357. {
  358. ctrl2_g.odr_g = (uint8_t) val;
  359. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL2_G,
  360. (uint8_t *)&ctrl2_g, 1);
  361. }
  362. return ret;
  363. }
  364. /**
  365. * @brief Gyroscope data rate selection.[get]
  366. *
  367. * @param ctx Read / write interface definitions
  368. * @param val Get the values of odr_g in reg CTRL2_G
  369. * @retval Interface status (MANDATORY: return 0 -> no Error).
  370. *
  371. */
  372. int32_t lsm6ds3tr_c_gy_data_rate_get(const stmdev_ctx_t *ctx,
  373. lsm6ds3tr_c_odr_g_t *val)
  374. {
  375. lsm6ds3tr_c_ctrl2_g_t ctrl2_g;
  376. int32_t ret;
  377. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL2_G,
  378. (uint8_t *)&ctrl2_g, 1);
  379. switch (ctrl2_g.odr_g)
  380. {
  381. case LSM6DS3TR_C_GY_ODR_OFF:
  382. *val = LSM6DS3TR_C_GY_ODR_OFF;
  383. break;
  384. case LSM6DS3TR_C_GY_ODR_12Hz5:
  385. *val = LSM6DS3TR_C_GY_ODR_12Hz5;
  386. break;
  387. case LSM6DS3TR_C_GY_ODR_26Hz:
  388. *val = LSM6DS3TR_C_GY_ODR_26Hz;
  389. break;
  390. case LSM6DS3TR_C_GY_ODR_52Hz:
  391. *val = LSM6DS3TR_C_GY_ODR_52Hz;
  392. break;
  393. case LSM6DS3TR_C_GY_ODR_104Hz:
  394. *val = LSM6DS3TR_C_GY_ODR_104Hz;
  395. break;
  396. case LSM6DS3TR_C_GY_ODR_208Hz:
  397. *val = LSM6DS3TR_C_GY_ODR_208Hz;
  398. break;
  399. case LSM6DS3TR_C_GY_ODR_416Hz:
  400. *val = LSM6DS3TR_C_GY_ODR_416Hz;
  401. break;
  402. case LSM6DS3TR_C_GY_ODR_833Hz:
  403. *val = LSM6DS3TR_C_GY_ODR_833Hz;
  404. break;
  405. case LSM6DS3TR_C_GY_ODR_1k66Hz:
  406. *val = LSM6DS3TR_C_GY_ODR_1k66Hz;
  407. break;
  408. case LSM6DS3TR_C_GY_ODR_3k33Hz:
  409. *val = LSM6DS3TR_C_GY_ODR_3k33Hz;
  410. break;
  411. case LSM6DS3TR_C_GY_ODR_6k66Hz:
  412. *val = LSM6DS3TR_C_GY_ODR_6k66Hz;
  413. break;
  414. default:
  415. *val = LSM6DS3TR_C_GY_ODR_ND;
  416. break;
  417. }
  418. return ret;
  419. }
  420. /**
  421. * @brief Block data update.[set]
  422. *
  423. * @param ctx Read / write interface definitions
  424. * @param val Change the values of bdu in reg CTRL3_C
  425. * @retval Interface status (MANDATORY: return 0 -> no Error).
  426. *
  427. */
  428. int32_t lsm6ds3tr_c_block_data_update_set(const stmdev_ctx_t *ctx,
  429. uint8_t val)
  430. {
  431. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  432. int32_t ret;
  433. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  434. (uint8_t *)&ctrl3_c, 1);
  435. if (ret == 0)
  436. {
  437. ctrl3_c.bdu = val;
  438. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  439. (uint8_t *)&ctrl3_c, 1);
  440. }
  441. return ret;
  442. }
  443. /**
  444. * @brief Block data update.[get]
  445. *
  446. * @param ctx Read / write interface definitions
  447. * @param val Change the values of bdu in reg CTRL3_C
  448. * @retval Interface status (MANDATORY: return 0 -> no Error).
  449. *
  450. */
  451. int32_t lsm6ds3tr_c_block_data_update_get(const stmdev_ctx_t *ctx,
  452. uint8_t *val)
  453. {
  454. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  455. int32_t ret;
  456. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  457. (uint8_t *)&ctrl3_c, 1);
  458. *val = ctrl3_c.bdu;
  459. return ret;
  460. }
  461. /**
  462. * @brief Weight of XL user offset bits of registers
  463. * X_OFS_USR(73h), Y_OFS_USR(74h), Z_OFS_USR(75h).[set]
  464. *
  465. * @param ctx Read / write interface definitions
  466. * @param val Change the values of usr_off_w in reg CTRL6_C
  467. * @retval Interface status (MANDATORY: return 0 -> no Error).
  468. *
  469. */
  470. int32_t lsm6ds3tr_c_xl_offset_weight_set(const stmdev_ctx_t *ctx,
  471. lsm6ds3tr_c_usr_off_w_t val)
  472. {
  473. lsm6ds3tr_c_ctrl6_c_t ctrl6_c;
  474. int32_t ret;
  475. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  476. (uint8_t *)&ctrl6_c, 1);
  477. if (ret == 0)
  478. {
  479. ctrl6_c.usr_off_w = (uint8_t) val;
  480. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  481. (uint8_t *)&ctrl6_c, 1);
  482. }
  483. return ret;
  484. }
  485. /**
  486. * @brief Weight of XL user offset bits of registers
  487. * X_OFS_USR(73h), Y_OFS_USR(74h), Z_OFS_USR(75h).[get]
  488. *
  489. * @param ctx Read / write interface definitions
  490. * @param val Get the values of usr_off_w in reg CTRL6_C
  491. * @retval Interface status (MANDATORY: return 0 -> no Error).
  492. *
  493. */
  494. int32_t lsm6ds3tr_c_xl_offset_weight_get(const stmdev_ctx_t *ctx,
  495. lsm6ds3tr_c_usr_off_w_t *val)
  496. {
  497. lsm6ds3tr_c_ctrl6_c_t ctrl6_c;
  498. int32_t ret;
  499. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  500. (uint8_t *)&ctrl6_c, 1);
  501. switch (ctrl6_c.usr_off_w)
  502. {
  503. case LSM6DS3TR_C_LSb_1mg:
  504. *val = LSM6DS3TR_C_LSb_1mg;
  505. break;
  506. case LSM6DS3TR_C_LSb_16mg:
  507. *val = LSM6DS3TR_C_LSb_16mg;
  508. break;
  509. default:
  510. *val = LSM6DS3TR_C_WEIGHT_ND;
  511. break;
  512. }
  513. return ret;
  514. }
  515. /**
  516. * @brief High-performance operating mode for accelerometer[set]
  517. *
  518. * @param ctx Read / write interface definitions
  519. * @param val Change the values of xl_hm_mode in reg CTRL6_C
  520. * @retval Interface status (MANDATORY: return 0 -> no Error).
  521. *
  522. */
  523. int32_t lsm6ds3tr_c_xl_power_mode_set(const stmdev_ctx_t *ctx,
  524. lsm6ds3tr_c_xl_hm_mode_t val)
  525. {
  526. lsm6ds3tr_c_ctrl6_c_t ctrl6_c;
  527. int32_t ret;
  528. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  529. (uint8_t *)&ctrl6_c, 1);
  530. if (ret == 0)
  531. {
  532. ctrl6_c.xl_hm_mode = (uint8_t) val;
  533. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  534. (uint8_t *)&ctrl6_c, 1);
  535. }
  536. return ret;
  537. }
  538. /**
  539. * @brief High-performance operating mode for accelerometer.[get]
  540. *
  541. * @param ctx Read / write interface definitions
  542. * @param val Get the values of xl_hm_mode in reg CTRL6_C
  543. * @retval Interface status (MANDATORY: return 0 -> no Error).
  544. *
  545. */
  546. int32_t lsm6ds3tr_c_xl_power_mode_get(const stmdev_ctx_t *ctx,
  547. lsm6ds3tr_c_xl_hm_mode_t *val)
  548. {
  549. lsm6ds3tr_c_ctrl6_c_t ctrl6_c;
  550. int32_t ret;
  551. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  552. (uint8_t *)&ctrl6_c, 1);
  553. switch (ctrl6_c.xl_hm_mode)
  554. {
  555. case LSM6DS3TR_C_XL_HIGH_PERFORMANCE:
  556. *val = LSM6DS3TR_C_XL_HIGH_PERFORMANCE;
  557. break;
  558. case LSM6DS3TR_C_XL_NORMAL:
  559. *val = LSM6DS3TR_C_XL_NORMAL;
  560. break;
  561. default:
  562. *val = LSM6DS3TR_C_XL_PW_MODE_ND;
  563. break;
  564. }
  565. return ret;
  566. }
  567. /**
  568. * @brief Source register rounding function on WAKE_UP_SRC (1Bh),
  569. * TAP_SRC (1Ch), D6D_SRC (1Dh), STATUS_REG (1Eh) and
  570. * FUNC_SRC1 (53h) registers in the primary interface.[set]
  571. *
  572. * @param ctx Read / write interface definitions
  573. * @param val Change the values of rounding_status in reg CTRL7_G
  574. * @retval Interface status (MANDATORY: return 0 -> no Error).
  575. *
  576. */
  577. int32_t lsm6ds3tr_c_rounding_on_status_set(const stmdev_ctx_t *ctx,
  578. lsm6ds3tr_c_rounding_status_t val)
  579. {
  580. lsm6ds3tr_c_ctrl7_g_t ctrl7_g;
  581. int32_t ret;
  582. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL7_G,
  583. (uint8_t *)&ctrl7_g, 1);
  584. if (ret == 0)
  585. {
  586. ctrl7_g.rounding_status = (uint8_t) val;
  587. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL7_G,
  588. (uint8_t *)&ctrl7_g, 1);
  589. }
  590. return ret;
  591. }
  592. /**
  593. * @brief Source register rounding function on WAKE_UP_SRC (1Bh),
  594. * TAP_SRC (1Ch), D6D_SRC (1Dh), STATUS_REG (1Eh) and
  595. * FUNC_SRC1 (53h) registers in the primary interface.[get]
  596. *
  597. * @param ctx Read / write interface definitions
  598. * @param val Get the values of rounding_status in reg CTRL7_G
  599. * @retval Interface status (MANDATORY: return 0 -> no Error).
  600. *
  601. */
  602. int32_t lsm6ds3tr_c_rounding_on_status_get(const stmdev_ctx_t *ctx,
  603. lsm6ds3tr_c_rounding_status_t *val)
  604. {
  605. lsm6ds3tr_c_ctrl7_g_t ctrl7_g;
  606. int32_t ret;
  607. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL7_G,
  608. (uint8_t *)&ctrl7_g, 1);
  609. switch (ctrl7_g.rounding_status)
  610. {
  611. case LSM6DS3TR_C_STAT_RND_DISABLE:
  612. *val = LSM6DS3TR_C_STAT_RND_DISABLE;
  613. break;
  614. case LSM6DS3TR_C_STAT_RND_ENABLE:
  615. *val = LSM6DS3TR_C_STAT_RND_ENABLE;
  616. break;
  617. default:
  618. *val = LSM6DS3TR_C_STAT_RND_ND;
  619. break;
  620. }
  621. return ret;
  622. }
  623. /**
  624. * @brief High-performance operating mode disable for gyroscope.[set]
  625. *
  626. * @param ctx Read / write interface definitions
  627. * @param val Change the values of g_hm_mode in reg CTRL7_G
  628. * @retval Interface status (MANDATORY: return 0 -> no Error).
  629. *
  630. */
  631. int32_t lsm6ds3tr_c_gy_power_mode_set(const stmdev_ctx_t *ctx,
  632. lsm6ds3tr_c_g_hm_mode_t val)
  633. {
  634. lsm6ds3tr_c_ctrl7_g_t ctrl7_g;
  635. int32_t ret;
  636. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL7_G,
  637. (uint8_t *)&ctrl7_g, 1);
  638. if (ret == 0)
  639. {
  640. ctrl7_g.g_hm_mode = (uint8_t) val;
  641. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL7_G,
  642. (uint8_t *)&ctrl7_g, 1);
  643. }
  644. return ret;
  645. }
  646. /**
  647. * @brief High-performance operating mode disable for gyroscope.[get]
  648. *
  649. * @param ctx Read / write interface definitions
  650. * @param val Get the values of g_hm_mode in reg CTRL7_G
  651. * @retval Interface status (MANDATORY: return 0 -> no Error).
  652. *
  653. */
  654. int32_t lsm6ds3tr_c_gy_power_mode_get(const stmdev_ctx_t *ctx,
  655. lsm6ds3tr_c_g_hm_mode_t *val)
  656. {
  657. lsm6ds3tr_c_ctrl7_g_t ctrl7_g;
  658. int32_t ret;
  659. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL7_G,
  660. (uint8_t *)&ctrl7_g, 1);
  661. switch (ctrl7_g.g_hm_mode)
  662. {
  663. case LSM6DS3TR_C_GY_HIGH_PERFORMANCE:
  664. *val = LSM6DS3TR_C_GY_HIGH_PERFORMANCE;
  665. break;
  666. case LSM6DS3TR_C_GY_NORMAL:
  667. *val = LSM6DS3TR_C_GY_NORMAL;
  668. break;
  669. default:
  670. *val = LSM6DS3TR_C_GY_PW_MODE_ND;
  671. break;
  672. }
  673. return ret;
  674. }
  675. /**
  676. * @brief Read all the interrupt/status flag of the device.[get]
  677. *
  678. * @param ctx Read / write interface definitions
  679. * @param val WAKE_UP_SRC, TAP_SRC, D6D_SRC, STATUS_REG,
  680. * FUNC_SRC1, FUNC_SRC2, WRIST_TILT_IA, A_WRIST_TILT_Mask
  681. * @retval Interface status (MANDATORY: return 0 -> no Error).
  682. *
  683. */
  684. int32_t lsm6ds3tr_c_all_sources_get(const stmdev_ctx_t *ctx,
  685. lsm6ds3tr_c_all_sources_t *val)
  686. {
  687. int32_t ret;
  688. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_SRC,
  689. (uint8_t *) & (val->wake_up_src), 1);
  690. if (ret == 0)
  691. {
  692. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_SRC,
  693. (uint8_t *) & (val->tap_src), 1);
  694. }
  695. if (ret == 0)
  696. {
  697. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_D6D_SRC,
  698. (uint8_t *) & (val->d6d_src), 1);
  699. }
  700. if (ret == 0)
  701. {
  702. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_STATUS_REG,
  703. (uint8_t *) & (val->status_reg), 1);
  704. }
  705. if (ret == 0)
  706. {
  707. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FUNC_SRC1,
  708. (uint8_t *) & (val->func_src1), 1);
  709. }
  710. if (ret == 0)
  711. {
  712. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FUNC_SRC2,
  713. (uint8_t *) & (val->func_src2), 1);
  714. }
  715. if (ret == 0)
  716. {
  717. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WRIST_TILT_IA,
  718. (uint8_t *) & (val->wrist_tilt_ia), 1);
  719. }
  720. if (ret == 0)
  721. {
  722. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_B);
  723. }
  724. if (ret == 0)
  725. {
  726. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_A_WRIST_TILT_MASK,
  727. (uint8_t *) & (val->a_wrist_tilt_mask), 1);
  728. }
  729. if (ret == 0)
  730. {
  731. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  732. }
  733. return ret;
  734. }
  735. /**
  736. * @brief The STATUS_REG register is read by the primary interface[get]
  737. *
  738. * @param ctx Read / write interface definitions
  739. * @param val Registers STATUS_REG
  740. * @retval Interface status (MANDATORY: return 0 -> no Error).
  741. *
  742. */
  743. int32_t lsm6ds3tr_c_status_reg_get(const stmdev_ctx_t *ctx,
  744. lsm6ds3tr_c_status_reg_t *val)
  745. {
  746. int32_t ret;
  747. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_STATUS_REG,
  748. (uint8_t *) val, 1);
  749. return ret;
  750. }
  751. /**
  752. * @brief Accelerometer new data available.[get]
  753. *
  754. * @param ctx Read / write interface definitions
  755. * @param val Change the values of xlda in reg STATUS_REG
  756. * @retval Interface status (MANDATORY: return 0 -> no Error).
  757. *
  758. */
  759. int32_t lsm6ds3tr_c_xl_flag_data_ready_get(const stmdev_ctx_t *ctx,
  760. uint8_t *val)
  761. {
  762. lsm6ds3tr_c_status_reg_t status_reg;
  763. int32_t ret;
  764. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_STATUS_REG,
  765. (uint8_t *)&status_reg, 1);
  766. *val = status_reg.xlda;
  767. return ret;
  768. }
  769. /**
  770. * @brief Gyroscope new data available.[get]
  771. *
  772. * @param ctx Read / write interface definitions
  773. * @param val Change the values of gda in reg STATUS_REG
  774. * @retval Interface status (MANDATORY: return 0 -> no Error).
  775. *
  776. */
  777. int32_t lsm6ds3tr_c_gy_flag_data_ready_get(const stmdev_ctx_t *ctx,
  778. uint8_t *val)
  779. {
  780. lsm6ds3tr_c_status_reg_t status_reg;
  781. int32_t ret;
  782. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_STATUS_REG,
  783. (uint8_t *)&status_reg, 1);
  784. *val = status_reg.gda;
  785. return ret;
  786. }
  787. /**
  788. * @brief Temperature new data available.[get]
  789. *
  790. * @param ctx Read / write interface definitions
  791. * @param val Change the values of tda in reg STATUS_REG
  792. * @retval Interface status (MANDATORY: return 0 -> no Error).
  793. *
  794. */
  795. int32_t lsm6ds3tr_c_temp_flag_data_ready_get(const stmdev_ctx_t *ctx,
  796. uint8_t *val)
  797. {
  798. lsm6ds3tr_c_status_reg_t status_reg;
  799. int32_t ret;
  800. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_STATUS_REG,
  801. (uint8_t *)&status_reg, 1);
  802. *val = status_reg.tda;
  803. return ret;
  804. }
  805. /**
  806. * @brief Accelerometer axis user offset correction expressed in two’s
  807. * complement, weight depends on USR_OFF_W in CTRL6_C.
  808. * The value must be in the range [-127 127].[set]
  809. *
  810. * @param ctx Read / write interface definitions
  811. * @param buff Buffer that contains data to write
  812. * @retval Interface status (MANDATORY: return 0 -> no Error).
  813. *
  814. */
  815. int32_t lsm6ds3tr_c_xl_usr_offset_set(const stmdev_ctx_t *ctx,
  816. uint8_t *buff)
  817. {
  818. int32_t ret;
  819. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_X_OFS_USR, buff, 3);
  820. return ret;
  821. }
  822. /**
  823. * @brief Accelerometer axis user offset correction xpressed in two’s
  824. * complement, weight depends on USR_OFF_W in CTRL6_C.
  825. * The value must be in the range [-127 127].[get]
  826. *
  827. * @param ctx Read / write interface definitions
  828. * @param buff Buffer that stores data read
  829. * @retval Interface status (MANDATORY: return 0 -> no Error).
  830. *
  831. */
  832. int32_t lsm6ds3tr_c_xl_usr_offset_get(const stmdev_ctx_t *ctx,
  833. uint8_t *buff)
  834. {
  835. int32_t ret;
  836. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_X_OFS_USR, buff, 3);
  837. return ret;
  838. }
  839. /**
  840. * @}
  841. *
  842. */
  843. /**
  844. * @defgroup LSM6DS3TR_C_Timestamp
  845. * @brief This section groups all the functions that manage the
  846. * timestamp generation.
  847. * @{
  848. *
  849. */
  850. /**
  851. * @brief Enable timestamp count. The count is saved in TIMESTAMP0_REG (40h),
  852. * TIMESTAMP1_REG (41h) and TIMESTAMP2_REG (42h).[set]
  853. *
  854. * @param ctx Read / write interface definitions
  855. * @param val Change the values of timer_en in reg CTRL10_C
  856. * @retval Interface status (MANDATORY: return 0 -> no Error).
  857. *
  858. */
  859. int32_t lsm6ds3tr_c_timestamp_set(const stmdev_ctx_t *ctx, uint8_t val)
  860. {
  861. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  862. int32_t ret;
  863. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  864. (uint8_t *)&ctrl10_c, 1);
  865. if (ret == 0)
  866. {
  867. ctrl10_c.timer_en = val;
  868. if (val != 0x00U)
  869. {
  870. ctrl10_c.func_en = val;
  871. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  872. (uint8_t *)&ctrl10_c, 1);
  873. }
  874. }
  875. return ret;
  876. }
  877. /**
  878. * @brief Enable timestamp count. The count is saved in TIMESTAMP0_REG (40h),
  879. * TIMESTAMP1_REG (41h) and TIMESTAMP2_REG (42h).[get]
  880. *
  881. * @param ctx Read / write interface definitions
  882. * @param val Change the values of timer_en in reg CTRL10_C
  883. * @retval Interface status (MANDATORY: return 0 -> no Error).
  884. *
  885. */
  886. int32_t lsm6ds3tr_c_timestamp_get(const stmdev_ctx_t *ctx, uint8_t *val)
  887. {
  888. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  889. int32_t ret;
  890. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  891. (uint8_t *)&ctrl10_c, 1);
  892. *val = ctrl10_c.timer_en;
  893. return ret;
  894. }
  895. /**
  896. * @brief Timestamp register resolution setting.
  897. * Configuration of this bit affects
  898. * TIMESTAMP0_REG(40h), TIMESTAMP1_REG(41h),
  899. * TIMESTAMP2_REG(42h), STEP_TIMESTAMP_L(49h),
  900. * STEP_TIMESTAMP_H(4Ah) and
  901. * STEP_COUNT_DELTA(15h) registers.[set]
  902. *
  903. * @param ctx Read / write interface definitions
  904. * @param val Change the values of timer_hr in reg WAKE_UP_DUR
  905. * @retval Interface status (MANDATORY: return 0 -> no Error).
  906. *
  907. */
  908. int32_t lsm6ds3tr_c_timestamp_res_set(const stmdev_ctx_t *ctx,
  909. lsm6ds3tr_c_timer_hr_t val)
  910. {
  911. lsm6ds3tr_c_wake_up_dur_t wake_up_dur;
  912. int32_t ret;
  913. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  914. (uint8_t *)&wake_up_dur, 1);
  915. if (ret == 0)
  916. {
  917. wake_up_dur.timer_hr = (uint8_t) val;
  918. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  919. (uint8_t *)&wake_up_dur, 1);
  920. }
  921. return ret;
  922. }
  923. /**
  924. * @brief Timestamp register resolution setting.
  925. * Configuration of this bit affects
  926. * TIMESTAMP0_REG(40h), TIMESTAMP1_REG(41h),
  927. * TIMESTAMP2_REG(42h), STEP_TIMESTAMP_L(49h),
  928. * STEP_TIMESTAMP_H(4Ah) and
  929. * STEP_COUNT_DELTA(15h) registers.[get]
  930. *
  931. * @param ctx Read / write interface definitions
  932. * @param val Get the values of timer_hr in reg WAKE_UP_DUR
  933. * @retval Interface status (MANDATORY: return 0 -> no Error).
  934. *
  935. */
  936. int32_t lsm6ds3tr_c_timestamp_res_get(const stmdev_ctx_t *ctx,
  937. lsm6ds3tr_c_timer_hr_t *val)
  938. {
  939. lsm6ds3tr_c_wake_up_dur_t wake_up_dur;
  940. int32_t ret;
  941. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  942. (uint8_t *)&wake_up_dur, 1);
  943. switch (wake_up_dur.timer_hr)
  944. {
  945. case LSM6DS3TR_C_LSB_6ms4:
  946. *val = LSM6DS3TR_C_LSB_6ms4;
  947. break;
  948. case LSM6DS3TR_C_LSB_25us:
  949. *val = LSM6DS3TR_C_LSB_25us;
  950. break;
  951. default:
  952. *val = LSM6DS3TR_C_TS_RES_ND;
  953. break;
  954. }
  955. return ret;
  956. }
  957. /**
  958. * @}
  959. *
  960. */
  961. /**
  962. * @defgroup LSM6DS3TR_C_Dataoutput
  963. * @brief This section groups all the data output functions.
  964. * @{
  965. *
  966. */
  967. /**
  968. * @brief Circular burst-mode (rounding) read from output registers
  969. * through the primary interface.[set]
  970. *
  971. * @param ctx Read / write interface definitions
  972. * @param val Change the values of rounding in reg CTRL5_C
  973. * @retval Interface status (MANDATORY: return 0 -> no Error).
  974. *
  975. */
  976. int32_t lsm6ds3tr_c_rounding_mode_set(const stmdev_ctx_t *ctx,
  977. lsm6ds3tr_c_rounding_t val)
  978. {
  979. lsm6ds3tr_c_ctrl5_c_t ctrl5_c;
  980. int32_t ret;
  981. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  982. (uint8_t *)&ctrl5_c, 1);
  983. if (ret == 0)
  984. {
  985. ctrl5_c.rounding = (uint8_t) val;
  986. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  987. (uint8_t *)&ctrl5_c, 1);
  988. }
  989. return ret;
  990. }
  991. /**
  992. * @brief Circular burst-mode (rounding) read from output registers
  993. * through the primary interface.[get]
  994. *
  995. * @param ctx Read / write interface definitions
  996. * @param val Get the values of rounding in reg CTRL5_C
  997. * @retval Interface status (MANDATORY: return 0 -> no Error).
  998. *
  999. */
  1000. int32_t lsm6ds3tr_c_rounding_mode_get(const stmdev_ctx_t *ctx,
  1001. lsm6ds3tr_c_rounding_t *val)
  1002. {
  1003. lsm6ds3tr_c_ctrl5_c_t ctrl5_c;
  1004. int32_t ret;
  1005. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  1006. (uint8_t *)&ctrl5_c, 1);
  1007. switch (ctrl5_c.rounding)
  1008. {
  1009. case LSM6DS3TR_C_ROUND_DISABLE:
  1010. *val = LSM6DS3TR_C_ROUND_DISABLE;
  1011. break;
  1012. case LSM6DS3TR_C_ROUND_XL:
  1013. *val = LSM6DS3TR_C_ROUND_XL;
  1014. break;
  1015. case LSM6DS3TR_C_ROUND_GY:
  1016. *val = LSM6DS3TR_C_ROUND_GY;
  1017. break;
  1018. case LSM6DS3TR_C_ROUND_GY_XL:
  1019. *val = LSM6DS3TR_C_ROUND_GY_XL;
  1020. break;
  1021. case LSM6DS3TR_C_ROUND_SH1_TO_SH6:
  1022. *val = LSM6DS3TR_C_ROUND_SH1_TO_SH6;
  1023. break;
  1024. case LSM6DS3TR_C_ROUND_XL_SH1_TO_SH6:
  1025. *val = LSM6DS3TR_C_ROUND_XL_SH1_TO_SH6;
  1026. break;
  1027. case LSM6DS3TR_C_ROUND_GY_XL_SH1_TO_SH12:
  1028. *val = LSM6DS3TR_C_ROUND_GY_XL_SH1_TO_SH12;
  1029. break;
  1030. case LSM6DS3TR_C_ROUND_GY_XL_SH1_TO_SH6:
  1031. *val = LSM6DS3TR_C_ROUND_GY_XL_SH1_TO_SH6;
  1032. break;
  1033. default:
  1034. *val = LSM6DS3TR_C_ROUND_OUT_ND;
  1035. break;
  1036. }
  1037. return ret;
  1038. }
  1039. /**
  1040. * @brief Temperature data output register (r). L and H registers together
  1041. * express a 16-bit word in two’s complement.[get]
  1042. *
  1043. * @param ctx Read / write interface definitions
  1044. * @param buff Buffer that stores data read
  1045. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1046. *
  1047. */
  1048. int32_t lsm6ds3tr_c_temperature_raw_get(const stmdev_ctx_t *ctx,
  1049. int16_t *val)
  1050. {
  1051. uint8_t buff[2];
  1052. int32_t ret;
  1053. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_OUT_TEMP_L, buff, 2);
  1054. *val = (int16_t)buff[1];
  1055. *val = (*val * 256) + (int16_t)buff[0];
  1056. return ret;
  1057. }
  1058. /**
  1059. * @brief Angular rate sensor. The value is expressed as a 16-bit word in
  1060. * two’s complement.[get]
  1061. *
  1062. * @param ctx Read / write interface definitions
  1063. * @param buff Buffer that stores data read
  1064. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1065. *
  1066. */
  1067. int32_t lsm6ds3tr_c_angular_rate_raw_get(const stmdev_ctx_t *ctx,
  1068. int16_t *val)
  1069. {
  1070. uint8_t buff[6];
  1071. int32_t ret;
  1072. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_OUTX_L_G, buff, 6);
  1073. val[0] = (int16_t)buff[1];
  1074. val[0] = (val[0] * 256) + (int16_t)buff[0];
  1075. val[1] = (int16_t)buff[3];
  1076. val[1] = (val[1] * 256) + (int16_t)buff[2];
  1077. val[2] = (int16_t)buff[5];
  1078. val[2] = (val[2] * 256) + (int16_t)buff[4];
  1079. return ret;
  1080. }
  1081. /**
  1082. * @brief Linear acceleration output register. The value is expressed
  1083. * as a 16-bit word in two’s complement.[get]
  1084. *
  1085. * @param ctx Read / write interface definitions
  1086. * @param buff Buffer that stores data read
  1087. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1088. *
  1089. */
  1090. int32_t lsm6ds3tr_c_acceleration_raw_get(const stmdev_ctx_t *ctx,
  1091. int16_t *val)
  1092. {
  1093. uint8_t buff[6];
  1094. int32_t ret;
  1095. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_OUTX_L_XL, buff, 6);
  1096. val[0] = (int16_t)buff[1];
  1097. val[0] = (val[0] * 256) + (int16_t)buff[0];
  1098. val[1] = (int16_t)buff[3];
  1099. val[1] = (val[1] * 256) + (int16_t)buff[2];
  1100. val[2] = (int16_t)buff[5];
  1101. val[2] = (val[2] * 256) + (int16_t)buff[4];
  1102. return ret;
  1103. }
  1104. /**
  1105. * @brief External magnetometer raw data.[get]
  1106. *
  1107. * @param ctx Read / write interface definitions
  1108. * @param buff Buffer that stores data read
  1109. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1110. *
  1111. */
  1112. int32_t lsm6ds3tr_c_mag_calibrated_raw_get(const stmdev_ctx_t *ctx,
  1113. int16_t *val)
  1114. {
  1115. uint8_t buff[6];
  1116. int32_t ret;
  1117. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_OUT_MAG_RAW_X_L, buff, 6);
  1118. val[0] = (int16_t)buff[1];
  1119. val[0] = (val[0] * 256) + (int16_t)buff[0];
  1120. val[1] = (int16_t)buff[3];
  1121. val[1] = (val[1] * 256) + (int16_t)buff[2];
  1122. val[2] = (int16_t)buff[5];
  1123. val[2] = (val[2] * 256) + (int16_t)buff[4];
  1124. return ret;
  1125. }
  1126. /**
  1127. * @brief Read data in FIFO.[get]
  1128. *
  1129. * @param ctx Read / write interface definitions
  1130. * @param buffer Data buffer to store FIFO data.
  1131. * @param len Number of data to read from FIFO.
  1132. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1133. *
  1134. */
  1135. int32_t lsm6ds3tr_c_fifo_raw_data_get(const stmdev_ctx_t *ctx,
  1136. uint8_t *buffer,
  1137. uint8_t len)
  1138. {
  1139. int32_t ret;
  1140. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_DATA_OUT_L, buffer,
  1141. len);
  1142. return ret;
  1143. }
  1144. /**
  1145. * @}
  1146. *
  1147. */
  1148. /**
  1149. * @defgroup LSM6DS3TR_C_common
  1150. * @brief This section groups common useful functions.
  1151. * @{
  1152. *
  1153. */
  1154. /**
  1155. * @brief Enable access to the embedded functions/sensor hub
  1156. * configuration registers[set]
  1157. *
  1158. * @param ctx Read / write interface definitions
  1159. * @param val Change the values of func_cfg_en in reg FUNC_CFG_ACCESS
  1160. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1161. *
  1162. */
  1163. int32_t lsm6ds3tr_c_mem_bank_set(const stmdev_ctx_t *ctx,
  1164. lsm6ds3tr_c_func_cfg_en_t val)
  1165. {
  1166. lsm6ds3tr_c_func_cfg_access_t func_cfg_access;
  1167. int32_t ret;
  1168. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FUNC_CFG_ACCESS,
  1169. (uint8_t *)&func_cfg_access, 1);
  1170. if (ret == 0)
  1171. {
  1172. func_cfg_access.func_cfg_en = (uint8_t) val;
  1173. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FUNC_CFG_ACCESS,
  1174. (uint8_t *)&func_cfg_access, 1);
  1175. }
  1176. return ret;
  1177. }
  1178. /**
  1179. * @brief Enable access to the embedded functions/sensor hub configuration
  1180. * registers[get]
  1181. *
  1182. * @param ctx Read / write interface definitions
  1183. * @param val Get the values of func_cfg_en in reg FUNC_CFG_ACCESS
  1184. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1185. *
  1186. */
  1187. int32_t lsm6ds3tr_c_mem_bank_get(const stmdev_ctx_t *ctx,
  1188. lsm6ds3tr_c_func_cfg_en_t *val)
  1189. {
  1190. lsm6ds3tr_c_func_cfg_access_t func_cfg_access;
  1191. int32_t ret;
  1192. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FUNC_CFG_ACCESS,
  1193. (uint8_t *)&func_cfg_access, 1);
  1194. switch (func_cfg_access.func_cfg_en)
  1195. {
  1196. case LSM6DS3TR_C_USER_BANK:
  1197. *val = LSM6DS3TR_C_USER_BANK;
  1198. break;
  1199. case LSM6DS3TR_C_BANK_B:
  1200. *val = LSM6DS3TR_C_BANK_B;
  1201. break;
  1202. default:
  1203. *val = LSM6DS3TR_C_BANK_ND;
  1204. break;
  1205. }
  1206. return ret;
  1207. }
  1208. /**
  1209. * @brief Data-ready pulsed / letched mode[set]
  1210. *
  1211. * @param ctx Read / write interface definitions
  1212. * @param val Change the values of drdy_pulsed in reg DRDY_PULSE_CFG
  1213. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1214. *
  1215. */
  1216. int32_t lsm6ds3tr_c_data_ready_mode_set(const stmdev_ctx_t *ctx,
  1217. lsm6ds3tr_c_drdy_pulsed_g_t val)
  1218. {
  1219. lsm6ds3tr_c_drdy_pulse_cfg_g_t drdy_pulse_cfg_g;
  1220. int32_t ret;
  1221. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_DRDY_PULSE_CFG_G,
  1222. (uint8_t *)&drdy_pulse_cfg_g, 1);
  1223. if (ret == 0)
  1224. {
  1225. drdy_pulse_cfg_g.drdy_pulsed = (uint8_t) val;
  1226. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_DRDY_PULSE_CFG_G,
  1227. (uint8_t *)&drdy_pulse_cfg_g, 1);
  1228. }
  1229. return ret;
  1230. }
  1231. /**
  1232. * @brief Data-ready pulsed / letched mode[get]
  1233. *
  1234. * @param ctx Read / write interface definitions
  1235. * @param val Get the values of drdy_pulsed in reg DRDY_PULSE_CFG
  1236. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1237. *
  1238. */
  1239. int32_t lsm6ds3tr_c_data_ready_mode_get(const stmdev_ctx_t *ctx,
  1240. lsm6ds3tr_c_drdy_pulsed_g_t *val)
  1241. {
  1242. lsm6ds3tr_c_drdy_pulse_cfg_g_t drdy_pulse_cfg_g;
  1243. int32_t ret;
  1244. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_DRDY_PULSE_CFG_G,
  1245. (uint8_t *)&drdy_pulse_cfg_g, 1);
  1246. switch (drdy_pulse_cfg_g.drdy_pulsed)
  1247. {
  1248. case LSM6DS3TR_C_DRDY_LATCHED:
  1249. *val = LSM6DS3TR_C_DRDY_LATCHED;
  1250. break;
  1251. case LSM6DS3TR_C_DRDY_PULSED:
  1252. *val = LSM6DS3TR_C_DRDY_PULSED;
  1253. break;
  1254. default:
  1255. *val = LSM6DS3TR_C_DRDY_ND;
  1256. break;
  1257. }
  1258. return ret;
  1259. }
  1260. /**
  1261. * @brief DeviceWhoamI.[get]
  1262. *
  1263. * @param ctx Read / write interface definitions
  1264. * @param buff Buffer that stores data read
  1265. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1266. *
  1267. */
  1268. int32_t lsm6ds3tr_c_device_id_get(const stmdev_ctx_t *ctx, uint8_t *buff)
  1269. {
  1270. int32_t ret;
  1271. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WHO_AM_I, buff, 1);
  1272. return ret;
  1273. }
  1274. /**
  1275. * @brief Software reset. Restore the default values in user registers[set]
  1276. *
  1277. * @param ctx Read / write interface definitions
  1278. * @param val Change the values of sw_reset in reg CTRL3_C
  1279. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1280. *
  1281. */
  1282. int32_t lsm6ds3tr_c_reset_set(const stmdev_ctx_t *ctx, uint8_t val)
  1283. {
  1284. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  1285. int32_t ret;
  1286. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1287. (uint8_t *)&ctrl3_c, 1);
  1288. if (ret == 0)
  1289. {
  1290. ctrl3_c.sw_reset = val;
  1291. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1292. (uint8_t *)&ctrl3_c, 1);
  1293. }
  1294. return ret;
  1295. }
  1296. /**
  1297. * @brief Software reset. Restore the default values in user registers[get]
  1298. *
  1299. * @param ctx Read / write interface definitions
  1300. * @param val Change the values of sw_reset in reg CTRL3_C
  1301. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1302. *
  1303. */
  1304. int32_t lsm6ds3tr_c_reset_get(const stmdev_ctx_t *ctx, uint8_t *val)
  1305. {
  1306. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  1307. int32_t ret;
  1308. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1309. (uint8_t *)&ctrl3_c, 1);
  1310. *val = ctrl3_c.sw_reset;
  1311. return ret;
  1312. }
  1313. /**
  1314. * @brief Big/Little Endian Data selection.[set]
  1315. *
  1316. * @param ctx Read / write interface definitions
  1317. * @param val Change the values of ble in reg CTRL3_C
  1318. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1319. *
  1320. */
  1321. int32_t lsm6ds3tr_c_data_format_set(const stmdev_ctx_t *ctx,
  1322. lsm6ds3tr_c_ble_t val)
  1323. {
  1324. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  1325. int32_t ret;
  1326. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1327. (uint8_t *)&ctrl3_c, 1);
  1328. if (ret == 0)
  1329. {
  1330. ctrl3_c.ble = (uint8_t) val;
  1331. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1332. (uint8_t *)&ctrl3_c, 1);
  1333. }
  1334. return ret;
  1335. }
  1336. /**
  1337. * @brief Big/Little Endian Data selection.[get]
  1338. *
  1339. * @param ctx Read / write interface definitions
  1340. * @param val Get the values of ble in reg CTRL3_C
  1341. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1342. *
  1343. */
  1344. int32_t lsm6ds3tr_c_data_format_get(const stmdev_ctx_t *ctx,
  1345. lsm6ds3tr_c_ble_t *val)
  1346. {
  1347. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  1348. int32_t ret;
  1349. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1350. (uint8_t *)&ctrl3_c, 1);
  1351. switch (ctrl3_c.ble)
  1352. {
  1353. case LSM6DS3TR_C_LSB_AT_LOW_ADD:
  1354. *val = LSM6DS3TR_C_LSB_AT_LOW_ADD;
  1355. break;
  1356. case LSM6DS3TR_C_MSB_AT_LOW_ADD:
  1357. *val = LSM6DS3TR_C_MSB_AT_LOW_ADD;
  1358. break;
  1359. default:
  1360. *val = LSM6DS3TR_C_DATA_FMT_ND;
  1361. break;
  1362. }
  1363. return ret;
  1364. }
  1365. /**
  1366. * @brief Register address automatically incremented during a multiple byte
  1367. * access with a serial interface.[set]
  1368. *
  1369. * @param ctx Read / write interface definitions
  1370. * @param val Change the values of if_inc in reg CTRL3_C
  1371. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1372. *
  1373. */
  1374. int32_t lsm6ds3tr_c_auto_increment_set(const stmdev_ctx_t *ctx, uint8_t val)
  1375. {
  1376. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  1377. int32_t ret;
  1378. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1379. (uint8_t *)&ctrl3_c, 1);
  1380. if (ret == 0)
  1381. {
  1382. ctrl3_c.if_inc = val;
  1383. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1384. (uint8_t *)&ctrl3_c, 1);
  1385. }
  1386. return ret;
  1387. }
  1388. /**
  1389. * @brief Register address automatically incremented during a multiple byte
  1390. * access with a serial interface.[get]
  1391. *
  1392. * @param ctx Read / write interface definitions
  1393. * @param val Change the values of if_inc in reg CTRL3_C
  1394. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1395. *
  1396. */
  1397. int32_t lsm6ds3tr_c_auto_increment_get(const stmdev_ctx_t *ctx,
  1398. uint8_t *val)
  1399. {
  1400. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  1401. int32_t ret;
  1402. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1403. (uint8_t *)&ctrl3_c, 1);
  1404. *val = ctrl3_c.if_inc;
  1405. return ret;
  1406. }
  1407. /**
  1408. * @brief Reboot memory content. Reload the calibration parameters.[set]
  1409. *
  1410. * @param ctx Read / write interface definitions
  1411. * @param val Change the values of boot in reg CTRL3_C
  1412. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1413. *
  1414. */
  1415. int32_t lsm6ds3tr_c_boot_set(const stmdev_ctx_t *ctx, uint8_t val)
  1416. {
  1417. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  1418. int32_t ret;
  1419. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1420. (uint8_t *)&ctrl3_c, 1);
  1421. if (ret == 0)
  1422. {
  1423. ctrl3_c.boot = val;
  1424. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1425. (uint8_t *)&ctrl3_c, 1);
  1426. }
  1427. return ret;
  1428. }
  1429. /**
  1430. * @brief Reboot memory content. Reload the calibration parameters.[get]
  1431. *
  1432. * @param ctx Read / write interface definitions
  1433. * @param val Change the values of boot in reg CTRL3_C
  1434. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1435. *
  1436. */
  1437. int32_t lsm6ds3tr_c_boot_get(const stmdev_ctx_t *ctx, uint8_t *val)
  1438. {
  1439. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  1440. int32_t ret;
  1441. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1442. (uint8_t *)&ctrl3_c, 1);
  1443. *val = ctrl3_c.boot;
  1444. return ret;
  1445. }
  1446. /**
  1447. * @brief Linear acceleration sensor self-test enable.[set]
  1448. *
  1449. * @param ctx Read / write interface definitions
  1450. * @param val Change the values of st_xl in reg CTRL5_C
  1451. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1452. *
  1453. */
  1454. int32_t lsm6ds3tr_c_xl_self_test_set(const stmdev_ctx_t *ctx,
  1455. lsm6ds3tr_c_st_xl_t val)
  1456. {
  1457. lsm6ds3tr_c_ctrl5_c_t ctrl5_c;
  1458. int32_t ret;
  1459. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  1460. (uint8_t *)&ctrl5_c, 1);
  1461. if (ret == 0)
  1462. {
  1463. ctrl5_c.st_xl = (uint8_t) val;
  1464. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  1465. (uint8_t *)&ctrl5_c, 1);
  1466. }
  1467. return ret;
  1468. }
  1469. /**
  1470. * @brief Linear acceleration sensor self-test enable.[get]
  1471. *
  1472. * @param ctx Read / write interface definitions
  1473. * @param val Get the values of st_xl in reg CTRL5_C
  1474. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1475. *
  1476. */
  1477. int32_t lsm6ds3tr_c_xl_self_test_get(const stmdev_ctx_t *ctx,
  1478. lsm6ds3tr_c_st_xl_t *val)
  1479. {
  1480. lsm6ds3tr_c_ctrl5_c_t ctrl5_c;
  1481. int32_t ret;
  1482. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  1483. (uint8_t *)&ctrl5_c, 1);
  1484. switch (ctrl5_c.st_xl)
  1485. {
  1486. case LSM6DS3TR_C_XL_ST_DISABLE:
  1487. *val = LSM6DS3TR_C_XL_ST_DISABLE;
  1488. break;
  1489. case LSM6DS3TR_C_XL_ST_POSITIVE:
  1490. *val = LSM6DS3TR_C_XL_ST_POSITIVE;
  1491. break;
  1492. case LSM6DS3TR_C_XL_ST_NEGATIVE:
  1493. *val = LSM6DS3TR_C_XL_ST_NEGATIVE;
  1494. break;
  1495. default:
  1496. *val = LSM6DS3TR_C_XL_ST_ND;
  1497. break;
  1498. }
  1499. return ret;
  1500. }
  1501. /**
  1502. * @brief Angular rate sensor self-test enable.[set]
  1503. *
  1504. * @param ctx Read / write interface definitions
  1505. * @param val Change the values of st_g in reg CTRL5_C
  1506. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1507. *
  1508. */
  1509. int32_t lsm6ds3tr_c_gy_self_test_set(const stmdev_ctx_t *ctx,
  1510. lsm6ds3tr_c_st_g_t val)
  1511. {
  1512. lsm6ds3tr_c_ctrl5_c_t ctrl5_c;
  1513. int32_t ret;
  1514. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  1515. (uint8_t *)&ctrl5_c, 1);
  1516. if (ret == 0)
  1517. {
  1518. ctrl5_c.st_g = (uint8_t) val;
  1519. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  1520. (uint8_t *)&ctrl5_c, 1);
  1521. }
  1522. return ret;
  1523. }
  1524. /**
  1525. * @brief Angular rate sensor self-test enable.[get]
  1526. *
  1527. * @param ctx Read / write interface definitions
  1528. * @param val Get the values of st_g in reg CTRL5_C
  1529. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1530. *
  1531. */
  1532. int32_t lsm6ds3tr_c_gy_self_test_get(const stmdev_ctx_t *ctx,
  1533. lsm6ds3tr_c_st_g_t *val)
  1534. {
  1535. lsm6ds3tr_c_ctrl5_c_t ctrl5_c;
  1536. int32_t ret;
  1537. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  1538. (uint8_t *)&ctrl5_c, 1);
  1539. switch (ctrl5_c.st_g)
  1540. {
  1541. case LSM6DS3TR_C_GY_ST_DISABLE:
  1542. *val = LSM6DS3TR_C_GY_ST_DISABLE;
  1543. break;
  1544. case LSM6DS3TR_C_GY_ST_POSITIVE:
  1545. *val = LSM6DS3TR_C_GY_ST_POSITIVE;
  1546. break;
  1547. case LSM6DS3TR_C_GY_ST_NEGATIVE:
  1548. *val = LSM6DS3TR_C_GY_ST_NEGATIVE;
  1549. break;
  1550. default:
  1551. *val = LSM6DS3TR_C_GY_ST_ND;
  1552. break;
  1553. }
  1554. return ret;
  1555. }
  1556. /**
  1557. * @}
  1558. *
  1559. */
  1560. /**
  1561. * @defgroup LSM6DS3TR_C_filters
  1562. * @brief This section group all the functions concerning the filters
  1563. * configuration that impact both accelerometer and gyro.
  1564. * @{
  1565. *
  1566. */
  1567. /**
  1568. * @brief Mask DRDY on pin (both XL & Gyro) until filter settling ends
  1569. * (XL and Gyro independently masked).[set]
  1570. *
  1571. * @param ctx Read / write interface definitions
  1572. * @param val Change the values of drdy_mask in reg CTRL4_C
  1573. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1574. *
  1575. */
  1576. int32_t lsm6ds3tr_c_filter_settling_mask_set(const stmdev_ctx_t *ctx,
  1577. uint8_t val)
  1578. {
  1579. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  1580. int32_t ret;
  1581. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  1582. (uint8_t *)&ctrl4_c, 1);
  1583. if (ret == 0)
  1584. {
  1585. ctrl4_c.drdy_mask = val;
  1586. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  1587. (uint8_t *)&ctrl4_c, 1);
  1588. }
  1589. return ret;
  1590. }
  1591. /**
  1592. * @brief Mask DRDY on pin (both XL & Gyro) until filter settling ends
  1593. * (XL and Gyro independently masked).[get]
  1594. *
  1595. * @param ctx Read / write interface definitions
  1596. * @param val Change the values of drdy_mask in reg CTRL4_C
  1597. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1598. *
  1599. */
  1600. int32_t lsm6ds3tr_c_filter_settling_mask_get(const stmdev_ctx_t *ctx,
  1601. uint8_t *val)
  1602. {
  1603. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  1604. int32_t ret;
  1605. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  1606. (uint8_t *)&ctrl4_c, 1);
  1607. *val = ctrl4_c.drdy_mask;
  1608. return ret;
  1609. }
  1610. /**
  1611. * @brief HPF or SLOPE filter selection on wake-up and Activity/Inactivity
  1612. * functions.[set]
  1613. *
  1614. * @param ctx Read / write interface definitions
  1615. * @param val Change the values of slope_fds in reg TAP_CFG
  1616. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1617. *
  1618. */
  1619. int32_t lsm6ds3tr_c_xl_hp_path_internal_set(const stmdev_ctx_t *ctx,
  1620. lsm6ds3tr_c_slope_fds_t val)
  1621. {
  1622. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  1623. int32_t ret;
  1624. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  1625. (uint8_t *)&tap_cfg, 1);
  1626. if (ret == 0)
  1627. {
  1628. tap_cfg.slope_fds = (uint8_t) val;
  1629. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  1630. (uint8_t *)&tap_cfg, 1);
  1631. }
  1632. return ret;
  1633. }
  1634. /**
  1635. * @brief HPF or SLOPE filter selection on wake-up and Activity/Inactivity
  1636. * functions.[get]
  1637. *
  1638. * @param ctx Read / write interface definitions
  1639. * @param val Get the values of slope_fds in reg TAP_CFG
  1640. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1641. *
  1642. */
  1643. int32_t lsm6ds3tr_c_xl_hp_path_internal_get(const stmdev_ctx_t *ctx,
  1644. lsm6ds3tr_c_slope_fds_t *val)
  1645. {
  1646. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  1647. int32_t ret;
  1648. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  1649. (uint8_t *)&tap_cfg, 1);
  1650. switch (tap_cfg.slope_fds)
  1651. {
  1652. case LSM6DS3TR_C_USE_SLOPE:
  1653. *val = LSM6DS3TR_C_USE_SLOPE;
  1654. break;
  1655. case LSM6DS3TR_C_USE_HPF:
  1656. *val = LSM6DS3TR_C_USE_HPF;
  1657. break;
  1658. default:
  1659. *val = LSM6DS3TR_C_HP_PATH_ND;
  1660. break;
  1661. }
  1662. return ret;
  1663. }
  1664. /**
  1665. * @}
  1666. *
  1667. */
  1668. /**
  1669. * @defgroup LSM6DS3TR_C_accelerometer_filters
  1670. * @brief This section group all the functions concerning the filters
  1671. * configuration that impact accelerometer in every mode.
  1672. * @{
  1673. *
  1674. */
  1675. /**
  1676. * @brief Accelerometer analog chain bandwidth selection (only for
  1677. * accelerometer ODR ≥ 1.67 kHz).[set]
  1678. *
  1679. * @param ctx Read / write interface definitions
  1680. * @param val Change the values of bw0_xl in reg CTRL1_XL
  1681. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1682. *
  1683. */
  1684. int32_t lsm6ds3tr_c_xl_filter_analog_set(const stmdev_ctx_t *ctx,
  1685. lsm6ds3tr_c_bw0_xl_t val)
  1686. {
  1687. lsm6ds3tr_c_ctrl1_xl_t ctrl1_xl;
  1688. int32_t ret;
  1689. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  1690. (uint8_t *)&ctrl1_xl, 1);
  1691. if (ret == 0)
  1692. {
  1693. ctrl1_xl.bw0_xl = (uint8_t) val;
  1694. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  1695. (uint8_t *)&ctrl1_xl, 1);
  1696. }
  1697. return ret;
  1698. }
  1699. /**
  1700. * @brief Accelerometer analog chain bandwidth selection (only for
  1701. * accelerometer ODR ≥ 1.67 kHz).[get]
  1702. *
  1703. * @param ctx Read / write interface definitions
  1704. * @param val Get the values of bw0_xl in reg CTRL1_XL
  1705. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1706. *
  1707. */
  1708. int32_t lsm6ds3tr_c_xl_filter_analog_get(const stmdev_ctx_t *ctx,
  1709. lsm6ds3tr_c_bw0_xl_t *val)
  1710. {
  1711. lsm6ds3tr_c_ctrl1_xl_t ctrl1_xl;
  1712. int32_t ret;
  1713. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  1714. (uint8_t *)&ctrl1_xl, 1);
  1715. switch (ctrl1_xl.bw0_xl)
  1716. {
  1717. case LSM6DS3TR_C_XL_ANA_BW_1k5Hz:
  1718. *val = LSM6DS3TR_C_XL_ANA_BW_1k5Hz;
  1719. break;
  1720. case LSM6DS3TR_C_XL_ANA_BW_400Hz:
  1721. *val = LSM6DS3TR_C_XL_ANA_BW_400Hz;
  1722. break;
  1723. default:
  1724. *val = LSM6DS3TR_C_XL_ANA_BW_ND;
  1725. break;
  1726. }
  1727. return ret;
  1728. }
  1729. /**
  1730. * @}
  1731. *
  1732. */
  1733. /**
  1734. * @defgroup LSM6DS3TR_C_accelerometer_filters
  1735. * @brief This section group all the functions concerning the filters
  1736. * configuration that impact accelerometer.
  1737. * @{
  1738. *
  1739. */
  1740. /**
  1741. * @brief Accelerometer digital LPF (LPF1) bandwidth selection LPF2 is
  1742. * not used.[set]
  1743. *
  1744. * @param ctx Read / write interface definitions
  1745. * @param val Change the values of lpf1_bw_sel in reg CTRL1_XL
  1746. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1747. *
  1748. */
  1749. int32_t lsm6ds3tr_c_xl_lp1_bandwidth_set(const stmdev_ctx_t *ctx,
  1750. lsm6ds3tr_c_lpf1_bw_sel_t val)
  1751. {
  1752. lsm6ds3tr_c_ctrl1_xl_t ctrl1_xl;
  1753. lsm6ds3tr_c_ctrl8_xl_t ctrl8_xl;
  1754. int32_t ret;
  1755. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  1756. (uint8_t *)&ctrl1_xl, 1);
  1757. if (ret == 0)
  1758. {
  1759. ctrl1_xl.lpf1_bw_sel = (uint8_t) val;
  1760. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  1761. (uint8_t *)&ctrl1_xl, 1);
  1762. if (ret == 0)
  1763. {
  1764. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1765. (uint8_t *)&ctrl8_xl, 1);
  1766. if (ret == 0)
  1767. {
  1768. ctrl8_xl.lpf2_xl_en = 0;
  1769. ctrl8_xl.hp_slope_xl_en = 0;
  1770. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1771. (uint8_t *)&ctrl8_xl, 1);
  1772. }
  1773. }
  1774. }
  1775. return ret;
  1776. }
  1777. /**
  1778. * @brief Accelerometer digital LPF (LPF1) bandwidth selection LPF2
  1779. * is not used.[get]
  1780. *
  1781. * @param ctx Read / write interface definitions
  1782. * @param val Get the values of lpf1_bw_sel in reg CTRL1_XL
  1783. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1784. *
  1785. */
  1786. int32_t lsm6ds3tr_c_xl_lp1_bandwidth_get(const stmdev_ctx_t *ctx,
  1787. lsm6ds3tr_c_lpf1_bw_sel_t *val)
  1788. {
  1789. lsm6ds3tr_c_ctrl1_xl_t ctrl1_xl;
  1790. lsm6ds3tr_c_ctrl8_xl_t ctrl8_xl;
  1791. int32_t ret;
  1792. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1793. (uint8_t *)&ctrl8_xl, 1);
  1794. if (ret == 0)
  1795. {
  1796. if ((ctrl8_xl.lpf2_xl_en != 0x00U) ||
  1797. (ctrl8_xl.hp_slope_xl_en != 0x00U))
  1798. {
  1799. *val = LSM6DS3TR_C_XL_LP1_NA;
  1800. }
  1801. else
  1802. {
  1803. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  1804. (uint8_t *)&ctrl1_xl, 1);
  1805. switch (ctrl1_xl.lpf1_bw_sel)
  1806. {
  1807. case LSM6DS3TR_C_XL_LP1_ODR_DIV_2:
  1808. *val = LSM6DS3TR_C_XL_LP1_ODR_DIV_2;
  1809. break;
  1810. case LSM6DS3TR_C_XL_LP1_ODR_DIV_4:
  1811. *val = LSM6DS3TR_C_XL_LP1_ODR_DIV_4;
  1812. break;
  1813. default:
  1814. *val = LSM6DS3TR_C_XL_LP1_NA;
  1815. break;
  1816. }
  1817. }
  1818. }
  1819. return ret;
  1820. }
  1821. /**
  1822. * @brief LPF2 on outputs[set]
  1823. *
  1824. * @param ctx Read / write interface definitions
  1825. * @param val Change the values of input_composite in reg CTRL8_XL
  1826. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1827. *
  1828. */
  1829. int32_t lsm6ds3tr_c_xl_lp2_bandwidth_set(const stmdev_ctx_t *ctx,
  1830. lsm6ds3tr_c_input_composite_t val)
  1831. {
  1832. lsm6ds3tr_c_ctrl8_xl_t ctrl8_xl;
  1833. int32_t ret;
  1834. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1835. (uint8_t *)&ctrl8_xl, 1);
  1836. if (ret == 0)
  1837. {
  1838. ctrl8_xl.input_composite = ((uint8_t) val & 0x10U) >> 4;
  1839. ctrl8_xl.hpcf_xl = (uint8_t) val & 0x03U;
  1840. ctrl8_xl.lpf2_xl_en = 1;
  1841. ctrl8_xl.hp_slope_xl_en = 0;
  1842. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1843. (uint8_t *)&ctrl8_xl, 1);
  1844. }
  1845. return ret;
  1846. }
  1847. /**
  1848. * @brief LPF2 on outputs[get]
  1849. *
  1850. * @param ctx Read / write interface definitions
  1851. * @param val Get the values of input_composite in reg CTRL8_XL
  1852. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1853. *
  1854. */
  1855. int32_t lsm6ds3tr_c_xl_lp2_bandwidth_get(const stmdev_ctx_t *ctx,
  1856. lsm6ds3tr_c_input_composite_t *val)
  1857. {
  1858. lsm6ds3tr_c_ctrl8_xl_t ctrl8_xl;
  1859. int32_t ret;
  1860. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1861. (uint8_t *)&ctrl8_xl, 1);
  1862. if (ret == 0)
  1863. {
  1864. if ((ctrl8_xl.lpf2_xl_en == 0x00U) ||
  1865. (ctrl8_xl.hp_slope_xl_en != 0x00U))
  1866. {
  1867. *val = LSM6DS3TR_C_XL_LP_NA;
  1868. }
  1869. else
  1870. {
  1871. switch ((ctrl8_xl.input_composite << 4) + ctrl8_xl.hpcf_xl)
  1872. {
  1873. case LSM6DS3TR_C_XL_LOW_LAT_LP_ODR_DIV_50:
  1874. *val = LSM6DS3TR_C_XL_LOW_LAT_LP_ODR_DIV_50;
  1875. break;
  1876. case LSM6DS3TR_C_XL_LOW_LAT_LP_ODR_DIV_100:
  1877. *val = LSM6DS3TR_C_XL_LOW_LAT_LP_ODR_DIV_100;
  1878. break;
  1879. case LSM6DS3TR_C_XL_LOW_LAT_LP_ODR_DIV_9:
  1880. *val = LSM6DS3TR_C_XL_LOW_LAT_LP_ODR_DIV_9;
  1881. break;
  1882. case LSM6DS3TR_C_XL_LOW_LAT_LP_ODR_DIV_400:
  1883. *val = LSM6DS3TR_C_XL_LOW_LAT_LP_ODR_DIV_400;
  1884. break;
  1885. case LSM6DS3TR_C_XL_LOW_NOISE_LP_ODR_DIV_50:
  1886. *val = LSM6DS3TR_C_XL_LOW_NOISE_LP_ODR_DIV_50;
  1887. break;
  1888. case LSM6DS3TR_C_XL_LOW_NOISE_LP_ODR_DIV_100:
  1889. *val = LSM6DS3TR_C_XL_LOW_NOISE_LP_ODR_DIV_100;
  1890. break;
  1891. case LSM6DS3TR_C_XL_LOW_NOISE_LP_ODR_DIV_9:
  1892. *val = LSM6DS3TR_C_XL_LOW_NOISE_LP_ODR_DIV_9;
  1893. break;
  1894. case LSM6DS3TR_C_XL_LOW_NOISE_LP_ODR_DIV_400:
  1895. *val = LSM6DS3TR_C_XL_LOW_NOISE_LP_ODR_DIV_400;
  1896. break;
  1897. default:
  1898. *val = LSM6DS3TR_C_XL_LP_NA;
  1899. break;
  1900. }
  1901. }
  1902. }
  1903. return ret;
  1904. }
  1905. /**
  1906. * @brief Enable HP filter reference mode.[set]
  1907. *
  1908. * @param ctx Read / write interface definitions
  1909. * @param val Change the values of hp_ref_mode in reg CTRL8_XL
  1910. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1911. *
  1912. */
  1913. int32_t lsm6ds3tr_c_xl_reference_mode_set(const stmdev_ctx_t *ctx,
  1914. uint8_t val)
  1915. {
  1916. lsm6ds3tr_c_ctrl8_xl_t ctrl8_xl;
  1917. int32_t ret;
  1918. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1919. (uint8_t *)&ctrl8_xl, 1);
  1920. if (ret == 0)
  1921. {
  1922. ctrl8_xl.hp_ref_mode = val;
  1923. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1924. (uint8_t *)&ctrl8_xl, 1);
  1925. }
  1926. return ret;
  1927. }
  1928. /**
  1929. * @brief Enable HP filter reference mode.[get]
  1930. *
  1931. * @param ctx Read / write interface definitions
  1932. * @param val Change the values of hp_ref_mode in reg CTRL8_XL
  1933. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1934. *
  1935. */
  1936. int32_t lsm6ds3tr_c_xl_reference_mode_get(const stmdev_ctx_t *ctx,
  1937. uint8_t *val)
  1938. {
  1939. lsm6ds3tr_c_ctrl8_xl_t ctrl8_xl;
  1940. int32_t ret;
  1941. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1942. (uint8_t *)&ctrl8_xl, 1);
  1943. *val = ctrl8_xl.hp_ref_mode;
  1944. return ret;
  1945. }
  1946. /**
  1947. * @brief High pass/Slope on outputs.[set]
  1948. *
  1949. * @param ctx Read / write interface definitions
  1950. * @param val Change the values of hpcf_xl in reg CTRL8_XL
  1951. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1952. *
  1953. */
  1954. int32_t lsm6ds3tr_c_xl_hp_bandwidth_set(const stmdev_ctx_t *ctx,
  1955. lsm6ds3tr_c_hpcf_xl_t val)
  1956. {
  1957. lsm6ds3tr_c_ctrl8_xl_t ctrl8_xl;
  1958. int32_t ret;
  1959. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1960. (uint8_t *)&ctrl8_xl, 1);
  1961. if (ret == 0)
  1962. {
  1963. ctrl8_xl.input_composite = 0;
  1964. ctrl8_xl.hpcf_xl = (uint8_t)val & 0x03U;
  1965. ctrl8_xl.hp_slope_xl_en = 1;
  1966. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1967. (uint8_t *)&ctrl8_xl, 1);
  1968. }
  1969. return ret;
  1970. }
  1971. /**
  1972. * @brief High pass/Slope on outputs.[get]
  1973. *
  1974. * @param ctx Read / write interface definitions
  1975. * @param val Get the values of hpcf_xl in reg CTRL8_XL
  1976. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1977. *
  1978. */
  1979. int32_t lsm6ds3tr_c_xl_hp_bandwidth_get(const stmdev_ctx_t *ctx,
  1980. lsm6ds3tr_c_hpcf_xl_t *val)
  1981. {
  1982. lsm6ds3tr_c_ctrl8_xl_t ctrl8_xl;
  1983. int32_t ret;
  1984. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1985. (uint8_t *)&ctrl8_xl, 1);
  1986. if (ctrl8_xl.hp_slope_xl_en == 0x00U)
  1987. {
  1988. *val = LSM6DS3TR_C_XL_HP_NA;
  1989. }
  1990. switch (ctrl8_xl.hpcf_xl)
  1991. {
  1992. case LSM6DS3TR_C_XL_HP_ODR_DIV_4:
  1993. *val = LSM6DS3TR_C_XL_HP_ODR_DIV_4;
  1994. break;
  1995. case LSM6DS3TR_C_XL_HP_ODR_DIV_100:
  1996. *val = LSM6DS3TR_C_XL_HP_ODR_DIV_100;
  1997. break;
  1998. case LSM6DS3TR_C_XL_HP_ODR_DIV_9:
  1999. *val = LSM6DS3TR_C_XL_HP_ODR_DIV_9;
  2000. break;
  2001. case LSM6DS3TR_C_XL_HP_ODR_DIV_400:
  2002. *val = LSM6DS3TR_C_XL_HP_ODR_DIV_400;
  2003. break;
  2004. default:
  2005. *val = LSM6DS3TR_C_XL_HP_NA;
  2006. break;
  2007. }
  2008. return ret;
  2009. }
  2010. /**
  2011. * @}
  2012. *
  2013. */
  2014. /**
  2015. * @defgroup LSM6DS3TR_C_gyroscope_filters
  2016. * @brief This section group all the functions concerning the filters
  2017. * configuration that impact gyroscope.
  2018. * @{
  2019. *
  2020. */
  2021. /**
  2022. * @brief Gyroscope low pass path bandwidth.[set]
  2023. *
  2024. * @param ctx Read / write interface definitions
  2025. * @param val gyroscope filtering chain configuration.
  2026. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2027. *
  2028. */
  2029. int32_t lsm6ds3tr_c_gy_band_pass_set(const stmdev_ctx_t *ctx,
  2030. lsm6ds3tr_c_lpf1_sel_g_t val)
  2031. {
  2032. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  2033. lsm6ds3tr_c_ctrl6_c_t ctrl6_c;
  2034. lsm6ds3tr_c_ctrl7_g_t ctrl7_g;
  2035. int32_t ret;
  2036. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL7_G,
  2037. (uint8_t *)&ctrl7_g, 1);
  2038. if (ret == 0)
  2039. {
  2040. ctrl7_g.hpm_g = ((uint8_t)val & 0x30U) >> 4;
  2041. ctrl7_g.hp_en_g = ((uint8_t)val & 0x80U) >> 7;
  2042. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL7_G,
  2043. (uint8_t *)&ctrl7_g, 1);
  2044. if (ret == 0)
  2045. {
  2046. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  2047. (uint8_t *)&ctrl6_c, 1);
  2048. if (ret == 0)
  2049. {
  2050. ctrl6_c.ftype = (uint8_t)val & 0x03U;
  2051. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  2052. (uint8_t *)&ctrl6_c, 1);
  2053. if (ret == 0)
  2054. {
  2055. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2056. (uint8_t *)&ctrl4_c, 1);
  2057. if (ret == 0)
  2058. {
  2059. ctrl4_c.lpf1_sel_g = ((uint8_t)val & 0x08U) >> 3;
  2060. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2061. (uint8_t *)&ctrl4_c, 1);
  2062. }
  2063. }
  2064. }
  2065. }
  2066. }
  2067. return ret;
  2068. }
  2069. /**
  2070. * @brief Gyroscope low pass path bandwidth.[get]
  2071. *
  2072. * @param ctx Read / write interface definitions
  2073. * @param val gyroscope filtering chain
  2074. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2075. *
  2076. */
  2077. int32_t lsm6ds3tr_c_gy_band_pass_get(const stmdev_ctx_t *ctx,
  2078. lsm6ds3tr_c_lpf1_sel_g_t *val)
  2079. {
  2080. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  2081. lsm6ds3tr_c_ctrl6_c_t ctrl6_c;
  2082. lsm6ds3tr_c_ctrl7_g_t ctrl7_g;
  2083. int32_t ret;
  2084. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  2085. (uint8_t *)&ctrl6_c, 1);
  2086. if (ret == 0)
  2087. {
  2088. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2089. (uint8_t *)&ctrl4_c, 1);
  2090. if (ret == 0)
  2091. {
  2092. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL7_G,
  2093. (uint8_t *)&ctrl7_g, 1);
  2094. switch ((ctrl7_g.hp_en_g << 7) + (ctrl7_g.hpm_g << 4) +
  2095. (ctrl4_c.lpf1_sel_g << 3) + ctrl6_c.ftype)
  2096. {
  2097. case LSM6DS3TR_C_HP_16mHz_LP2:
  2098. *val = LSM6DS3TR_C_HP_16mHz_LP2;
  2099. break;
  2100. case LSM6DS3TR_C_HP_65mHz_LP2:
  2101. *val = LSM6DS3TR_C_HP_65mHz_LP2;
  2102. break;
  2103. case LSM6DS3TR_C_HP_260mHz_LP2:
  2104. *val = LSM6DS3TR_C_HP_260mHz_LP2;
  2105. break;
  2106. case LSM6DS3TR_C_HP_1Hz04_LP2:
  2107. *val = LSM6DS3TR_C_HP_1Hz04_LP2;
  2108. break;
  2109. case LSM6DS3TR_C_HP_DISABLE_LP1_LIGHT:
  2110. *val = LSM6DS3TR_C_HP_DISABLE_LP1_LIGHT;
  2111. break;
  2112. case LSM6DS3TR_C_HP_DISABLE_LP1_NORMAL:
  2113. *val = LSM6DS3TR_C_HP_DISABLE_LP1_NORMAL;
  2114. break;
  2115. case LSM6DS3TR_C_HP_DISABLE_LP_STRONG:
  2116. *val = LSM6DS3TR_C_HP_DISABLE_LP_STRONG;
  2117. break;
  2118. case LSM6DS3TR_C_HP_DISABLE_LP1_AGGRESSIVE:
  2119. *val = LSM6DS3TR_C_HP_DISABLE_LP1_AGGRESSIVE;
  2120. break;
  2121. case LSM6DS3TR_C_HP_16mHz_LP1_LIGHT:
  2122. *val = LSM6DS3TR_C_HP_16mHz_LP1_LIGHT;
  2123. break;
  2124. case LSM6DS3TR_C_HP_65mHz_LP1_NORMAL:
  2125. *val = LSM6DS3TR_C_HP_65mHz_LP1_NORMAL;
  2126. break;
  2127. case LSM6DS3TR_C_HP_260mHz_LP1_STRONG:
  2128. *val = LSM6DS3TR_C_HP_260mHz_LP1_STRONG;
  2129. break;
  2130. case LSM6DS3TR_C_HP_1Hz04_LP1_AGGRESSIVE:
  2131. *val = LSM6DS3TR_C_HP_1Hz04_LP1_AGGRESSIVE;
  2132. break;
  2133. default:
  2134. *val = LSM6DS3TR_C_HP_GY_BAND_NA;
  2135. break;
  2136. }
  2137. }
  2138. }
  2139. return ret;
  2140. }
  2141. /**
  2142. * @}
  2143. *
  2144. */
  2145. /**
  2146. * @defgroup LSM6DS3TR_C_serial_interface
  2147. * @brief This section groups all the functions concerning serial
  2148. * interface management
  2149. * @{
  2150. *
  2151. */
  2152. /**
  2153. * @brief SPI Serial Interface Mode selection.[set]
  2154. *
  2155. * @param ctx Read / write interface definitions
  2156. * @param val Change the values of sim in reg CTRL3_C
  2157. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2158. *
  2159. */
  2160. int32_t lsm6ds3tr_c_spi_mode_set(const stmdev_ctx_t *ctx,
  2161. lsm6ds3tr_c_sim_t val)
  2162. {
  2163. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  2164. int32_t ret;
  2165. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  2166. (uint8_t *)&ctrl3_c, 1);
  2167. if (ret == 0)
  2168. {
  2169. ctrl3_c.sim = (uint8_t) val;
  2170. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  2171. (uint8_t *)&ctrl3_c, 1);
  2172. }
  2173. return ret;
  2174. }
  2175. /**
  2176. * @brief SPI Serial Interface Mode selection.[get]
  2177. *
  2178. * @param ctx Read / write interface definitions
  2179. * @param val Get the values of sim in reg CTRL3_C
  2180. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2181. *
  2182. */
  2183. int32_t lsm6ds3tr_c_spi_mode_get(const stmdev_ctx_t *ctx,
  2184. lsm6ds3tr_c_sim_t *val)
  2185. {
  2186. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  2187. int32_t ret;
  2188. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  2189. (uint8_t *)&ctrl3_c, 1);
  2190. switch (ctrl3_c.sim)
  2191. {
  2192. case LSM6DS3TR_C_SPI_4_WIRE:
  2193. *val = LSM6DS3TR_C_SPI_4_WIRE;
  2194. break;
  2195. case LSM6DS3TR_C_SPI_3_WIRE:
  2196. *val = LSM6DS3TR_C_SPI_3_WIRE;
  2197. break;
  2198. default:
  2199. *val = LSM6DS3TR_C_SPI_MODE_ND;
  2200. break;
  2201. }
  2202. return ret;
  2203. }
  2204. /**
  2205. * @brief Disable / Enable I2C interface.[set]
  2206. *
  2207. * @param ctx Read / write interface definitions
  2208. * @param val Change the values of i2c_disable in reg CTRL4_C
  2209. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2210. *
  2211. */
  2212. int32_t lsm6ds3tr_c_i2c_interface_set(const stmdev_ctx_t *ctx,
  2213. lsm6ds3tr_c_i2c_disable_t val)
  2214. {
  2215. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  2216. int32_t ret;
  2217. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2218. (uint8_t *)&ctrl4_c, 1);
  2219. if (ret == 0)
  2220. {
  2221. ctrl4_c.i2c_disable = (uint8_t)val;
  2222. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2223. (uint8_t *)&ctrl4_c, 1);
  2224. }
  2225. return ret;
  2226. }
  2227. /**
  2228. * @brief Disable / Enable I2C interface.[get]
  2229. *
  2230. * @param ctx Read / write interface definitions
  2231. * @param val Get the values of i2c_disable in reg CTRL4_C
  2232. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2233. *
  2234. */
  2235. int32_t lsm6ds3tr_c_i2c_interface_get(const stmdev_ctx_t *ctx,
  2236. lsm6ds3tr_c_i2c_disable_t *val)
  2237. {
  2238. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  2239. int32_t ret;
  2240. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2241. (uint8_t *)&ctrl4_c, 1);
  2242. switch (ctrl4_c.i2c_disable)
  2243. {
  2244. case LSM6DS3TR_C_I2C_ENABLE:
  2245. *val = LSM6DS3TR_C_I2C_ENABLE;
  2246. break;
  2247. case LSM6DS3TR_C_I2C_DISABLE:
  2248. *val = LSM6DS3TR_C_I2C_DISABLE;
  2249. break;
  2250. default:
  2251. *val = LSM6DS3TR_C_I2C_MODE_ND;
  2252. break;
  2253. }
  2254. return ret;
  2255. }
  2256. /**
  2257. * @}
  2258. *
  2259. */
  2260. /**
  2261. * @defgroup LSM6DS3TR_C_interrupt_pins
  2262. * @brief This section groups all the functions that manage
  2263. * interrupt pins
  2264. * @{
  2265. *
  2266. */
  2267. /**
  2268. * @brief Select the signal that need to route on int1 pad[set]
  2269. *
  2270. * @param ctx Read / write interface definitions
  2271. * @param val configure INT1_CTRL, MD1_CFG, CTRL4_C(den_drdy_int1),
  2272. * MASTER_CONFIG(drdy_on_int1)
  2273. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2274. *
  2275. */
  2276. int32_t lsm6ds3tr_c_pin_int1_route_set(const stmdev_ctx_t *ctx,
  2277. lsm6ds3tr_c_int1_route_t val)
  2278. {
  2279. lsm6ds3tr_c_master_config_t master_config;
  2280. lsm6ds3tr_c_int1_ctrl_t int1_ctrl;
  2281. lsm6ds3tr_c_md1_cfg_t md1_cfg;
  2282. lsm6ds3tr_c_md2_cfg_t md2_cfg;
  2283. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  2284. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  2285. int32_t ret;
  2286. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_INT1_CTRL,
  2287. (uint8_t *)&int1_ctrl, 1);
  2288. if (ret == 0)
  2289. {
  2290. int1_ctrl.int1_drdy_xl = val.int1_drdy_xl;
  2291. int1_ctrl.int1_drdy_g = val.int1_drdy_g;
  2292. int1_ctrl.int1_boot = val.int1_boot;
  2293. int1_ctrl.int1_fth = val.int1_fth;
  2294. int1_ctrl.int1_fifo_ovr = val.int1_fifo_ovr;
  2295. int1_ctrl.int1_full_flag = val.int1_full_flag;
  2296. int1_ctrl.int1_sign_mot = val.int1_sign_mot;
  2297. int1_ctrl.int1_step_detector = val.int1_step_detector;
  2298. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_INT1_CTRL,
  2299. (uint8_t *)&int1_ctrl, 1);
  2300. }
  2301. if (ret == 0)
  2302. {
  2303. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MD1_CFG,
  2304. (uint8_t *)&md1_cfg, 1);
  2305. }
  2306. if (ret == 0)
  2307. {
  2308. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MD2_CFG,
  2309. (uint8_t *)&md2_cfg, 1);
  2310. }
  2311. if (ret == 0)
  2312. {
  2313. md1_cfg.int1_timer = val.int1_timer;
  2314. md1_cfg.int1_tilt = val.int1_tilt;
  2315. md1_cfg.int1_6d = val.int1_6d;
  2316. md1_cfg.int1_double_tap = val.int1_double_tap;
  2317. md1_cfg.int1_ff = val.int1_ff;
  2318. md1_cfg.int1_wu = val.int1_wu;
  2319. md1_cfg.int1_single_tap = val.int1_single_tap;
  2320. md1_cfg.int1_inact_state = val.int1_inact_state;
  2321. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MD1_CFG,
  2322. (uint8_t *)&md1_cfg, 1);
  2323. }
  2324. if (ret == 0)
  2325. {
  2326. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2327. (uint8_t *)&ctrl4_c, 1);
  2328. }
  2329. if (ret == 0)
  2330. {
  2331. ctrl4_c.den_drdy_int1 = val.den_drdy_int1;
  2332. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2333. (uint8_t *)&ctrl4_c, 1);
  2334. }
  2335. if (ret == 0)
  2336. {
  2337. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  2338. (uint8_t *)&master_config, 1);
  2339. }
  2340. if (ret == 0)
  2341. {
  2342. master_config.drdy_on_int1 = val.den_drdy_int1;
  2343. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  2344. (uint8_t *)&master_config, 1);
  2345. }
  2346. if (ret == 0)
  2347. {
  2348. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  2349. (uint8_t *)&tap_cfg, 1);
  2350. if ((val.int1_6d != 0x00U) ||
  2351. (val.int1_ff != 0x00U) ||
  2352. (val.int1_wu != 0x00U) ||
  2353. (val.int1_single_tap != 0x00U) ||
  2354. (val.int1_double_tap != 0x00U) ||
  2355. (val.int1_inact_state != 0x00U) ||
  2356. (md2_cfg.int2_6d != 0x00U) ||
  2357. (md2_cfg.int2_ff != 0x00U) ||
  2358. (md2_cfg.int2_wu != 0x00U) ||
  2359. (md2_cfg.int2_single_tap != 0x00U) ||
  2360. (md2_cfg.int2_double_tap != 0x00U) ||
  2361. (md2_cfg.int2_inact_state != 0x00U))
  2362. {
  2363. tap_cfg.interrupts_enable = PROPERTY_ENABLE;
  2364. }
  2365. else
  2366. {
  2367. tap_cfg.interrupts_enable = PROPERTY_DISABLE;
  2368. }
  2369. }
  2370. if (ret == 0)
  2371. {
  2372. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  2373. (uint8_t *)&tap_cfg, 1);
  2374. }
  2375. return ret;
  2376. }
  2377. /**
  2378. * @brief Select the signal that need to route on int1 pad[get]
  2379. *
  2380. * @param ctx Read / write interface definitions
  2381. * @param val read INT1_CTRL, MD1_CFG, CTRL4_C(den_drdy_int1),
  2382. * MASTER_CONFIG(drdy_on_int1)
  2383. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2384. *
  2385. */
  2386. int32_t lsm6ds3tr_c_pin_int1_route_get(const stmdev_ctx_t *ctx,
  2387. lsm6ds3tr_c_int1_route_t *val)
  2388. {
  2389. lsm6ds3tr_c_master_config_t master_config;
  2390. lsm6ds3tr_c_int1_ctrl_t int1_ctrl;
  2391. lsm6ds3tr_c_md1_cfg_t md1_cfg;
  2392. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  2393. int32_t ret;
  2394. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_INT1_CTRL,
  2395. (uint8_t *)&int1_ctrl, 1);
  2396. if (ret == 0)
  2397. {
  2398. val->int1_drdy_xl = int1_ctrl.int1_drdy_xl;
  2399. val->int1_drdy_g = int1_ctrl.int1_drdy_g;
  2400. val->int1_boot = int1_ctrl.int1_boot;
  2401. val->int1_fth = int1_ctrl.int1_fth;
  2402. val->int1_fifo_ovr = int1_ctrl.int1_fifo_ovr;
  2403. val->int1_full_flag = int1_ctrl.int1_full_flag;
  2404. val->int1_sign_mot = int1_ctrl.int1_sign_mot;
  2405. val->int1_step_detector = int1_ctrl.int1_step_detector ;
  2406. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MD1_CFG,
  2407. (uint8_t *)&md1_cfg, 1);
  2408. if (ret == 0)
  2409. {
  2410. val->int1_timer = md1_cfg.int1_timer;
  2411. val->int1_tilt = md1_cfg.int1_tilt;
  2412. val->int1_6d = md1_cfg.int1_6d;
  2413. val->int1_double_tap = md1_cfg.int1_double_tap;
  2414. val->int1_ff = md1_cfg.int1_ff;
  2415. val->int1_wu = md1_cfg.int1_wu;
  2416. val->int1_single_tap = md1_cfg.int1_single_tap;
  2417. val->int1_inact_state = md1_cfg.int1_inact_state;
  2418. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2419. (uint8_t *)&ctrl4_c, 1);
  2420. if (ret == 0)
  2421. {
  2422. val->den_drdy_int1 = ctrl4_c.den_drdy_int1;
  2423. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  2424. (uint8_t *)&master_config, 1);
  2425. val->den_drdy_int1 = master_config.drdy_on_int1;
  2426. }
  2427. }
  2428. }
  2429. return ret;
  2430. }
  2431. /**
  2432. * @brief Select the signal that need to route on int2 pad[set]
  2433. *
  2434. * @param ctx Read / write interface definitions
  2435. * @param val INT2_CTRL, DRDY_PULSE_CFG(int2_wrist_tilt), MD2_CFG
  2436. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2437. *
  2438. */
  2439. int32_t lsm6ds3tr_c_pin_int2_route_set(const stmdev_ctx_t *ctx,
  2440. lsm6ds3tr_c_int2_route_t val)
  2441. {
  2442. lsm6ds3tr_c_int2_ctrl_t int2_ctrl;
  2443. lsm6ds3tr_c_md1_cfg_t md1_cfg;
  2444. lsm6ds3tr_c_md2_cfg_t md2_cfg;
  2445. lsm6ds3tr_c_drdy_pulse_cfg_g_t drdy_pulse_cfg_g;
  2446. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  2447. int32_t ret;
  2448. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_INT2_CTRL,
  2449. (uint8_t *)&int2_ctrl, 1);
  2450. if (ret == 0)
  2451. {
  2452. int2_ctrl.int2_drdy_xl = val.int2_drdy_xl;
  2453. int2_ctrl.int2_drdy_g = val.int2_drdy_g;
  2454. int2_ctrl.int2_drdy_temp = val.int2_drdy_temp;
  2455. int2_ctrl.int2_fth = val.int2_fth;
  2456. int2_ctrl.int2_fifo_ovr = val.int2_fifo_ovr;
  2457. int2_ctrl.int2_full_flag = val.int2_full_flag;
  2458. int2_ctrl.int2_step_count_ov = val.int2_step_count_ov;
  2459. int2_ctrl.int2_step_delta = val.int2_step_delta;
  2460. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_INT2_CTRL,
  2461. (uint8_t *)&int2_ctrl, 1);
  2462. }
  2463. if (ret == 0)
  2464. {
  2465. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MD1_CFG,
  2466. (uint8_t *)&md1_cfg, 1);
  2467. }
  2468. if (ret == 0)
  2469. {
  2470. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MD2_CFG,
  2471. (uint8_t *)&md2_cfg, 1);
  2472. }
  2473. if (ret == 0)
  2474. {
  2475. md2_cfg.int2_iron = val.int2_iron;
  2476. md2_cfg.int2_tilt = val.int2_tilt;
  2477. md2_cfg.int2_6d = val.int2_6d;
  2478. md2_cfg.int2_double_tap = val.int2_double_tap;
  2479. md2_cfg.int2_ff = val.int2_ff;
  2480. md2_cfg.int2_wu = val.int2_wu;
  2481. md2_cfg.int2_single_tap = val.int2_single_tap;
  2482. md2_cfg.int2_inact_state = val.int2_inact_state;
  2483. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MD2_CFG,
  2484. (uint8_t *)&md2_cfg, 1);
  2485. }
  2486. if (ret == 0)
  2487. {
  2488. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_DRDY_PULSE_CFG_G,
  2489. (uint8_t *)&drdy_pulse_cfg_g, 1);
  2490. }
  2491. if (ret == 0)
  2492. {
  2493. drdy_pulse_cfg_g.int2_wrist_tilt = val.int2_wrist_tilt;
  2494. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_DRDY_PULSE_CFG_G,
  2495. (uint8_t *)&drdy_pulse_cfg_g, 1);
  2496. }
  2497. if (ret == 0)
  2498. {
  2499. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  2500. (uint8_t *)&tap_cfg, 1);
  2501. if ((md1_cfg.int1_6d != 0x00U) ||
  2502. (md1_cfg.int1_ff != 0x00U) ||
  2503. (md1_cfg.int1_wu != 0x00U) ||
  2504. (md1_cfg.int1_single_tap != 0x00U) ||
  2505. (md1_cfg.int1_double_tap != 0x00U) ||
  2506. (md1_cfg.int1_inact_state != 0x00U) ||
  2507. (val.int2_6d != 0x00U) ||
  2508. (val.int2_ff != 0x00U) ||
  2509. (val.int2_wu != 0x00U) ||
  2510. (val.int2_single_tap != 0x00U) ||
  2511. (val.int2_double_tap != 0x00U) ||
  2512. (val.int2_inact_state != 0x00U))
  2513. {
  2514. tap_cfg.interrupts_enable = PROPERTY_ENABLE;
  2515. }
  2516. else
  2517. {
  2518. tap_cfg.interrupts_enable = PROPERTY_DISABLE;
  2519. }
  2520. }
  2521. if (ret == 0)
  2522. {
  2523. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  2524. (uint8_t *)&tap_cfg, 1);
  2525. }
  2526. return ret;
  2527. }
  2528. /**
  2529. * @brief Select the signal that need to route on int2 pad[get]
  2530. *
  2531. * @param ctx Read / write interface definitions
  2532. * @param val INT2_CTRL, DRDY_PULSE_CFG(int2_wrist_tilt), MD2_CFG
  2533. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2534. *
  2535. */
  2536. int32_t lsm6ds3tr_c_pin_int2_route_get(const stmdev_ctx_t *ctx,
  2537. lsm6ds3tr_c_int2_route_t *val)
  2538. {
  2539. lsm6ds3tr_c_int2_ctrl_t int2_ctrl;
  2540. lsm6ds3tr_c_md2_cfg_t md2_cfg;
  2541. lsm6ds3tr_c_drdy_pulse_cfg_g_t drdy_pulse_cfg_g;
  2542. int32_t ret;
  2543. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_INT2_CTRL,
  2544. (uint8_t *)&int2_ctrl, 1);
  2545. if (ret == 0)
  2546. {
  2547. val->int2_drdy_xl = int2_ctrl.int2_drdy_xl;
  2548. val->int2_drdy_g = int2_ctrl.int2_drdy_g;
  2549. val->int2_drdy_temp = int2_ctrl.int2_drdy_temp;
  2550. val->int2_fth = int2_ctrl.int2_fth;
  2551. val->int2_fifo_ovr = int2_ctrl.int2_fifo_ovr;
  2552. val->int2_full_flag = int2_ctrl.int2_full_flag;
  2553. val->int2_step_count_ov = int2_ctrl.int2_step_count_ov;
  2554. val->int2_step_delta = int2_ctrl.int2_step_delta;
  2555. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MD2_CFG,
  2556. (uint8_t *)&md2_cfg, 1);
  2557. if (ret == 0)
  2558. {
  2559. val->int2_iron = md2_cfg.int2_iron;
  2560. val->int2_tilt = md2_cfg.int2_tilt;
  2561. val->int2_6d = md2_cfg.int2_6d;
  2562. val->int2_double_tap = md2_cfg.int2_double_tap;
  2563. val->int2_ff = md2_cfg.int2_ff;
  2564. val->int2_wu = md2_cfg.int2_wu;
  2565. val->int2_single_tap = md2_cfg.int2_single_tap;
  2566. val->int2_inact_state = md2_cfg.int2_inact_state;
  2567. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_DRDY_PULSE_CFG_G,
  2568. (uint8_t *)&drdy_pulse_cfg_g, 1);
  2569. val->int2_wrist_tilt = drdy_pulse_cfg_g.int2_wrist_tilt;
  2570. }
  2571. }
  2572. return ret;
  2573. }
  2574. /**
  2575. * @brief Push-pull/open drain selection on interrupt pads.[set]
  2576. *
  2577. * @param ctx Read / write interface definitions
  2578. * @param val Change the values of pp_od in reg CTRL3_C
  2579. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2580. *
  2581. */
  2582. int32_t lsm6ds3tr_c_pin_mode_set(const stmdev_ctx_t *ctx,
  2583. lsm6ds3tr_c_pp_od_t val)
  2584. {
  2585. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  2586. int32_t ret;
  2587. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  2588. (uint8_t *)&ctrl3_c, 1);
  2589. if (ret == 0)
  2590. {
  2591. ctrl3_c.pp_od = (uint8_t) val;
  2592. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  2593. (uint8_t *)&ctrl3_c, 1);
  2594. }
  2595. return ret;
  2596. }
  2597. /**
  2598. * @brief Push-pull/open drain selection on interrupt pads.[get]
  2599. *
  2600. * @param ctx Read / write interface definitions
  2601. * @param val Get the values of pp_od in reg CTRL3_C
  2602. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2603. *
  2604. */
  2605. int32_t lsm6ds3tr_c_pin_mode_get(const stmdev_ctx_t *ctx,
  2606. lsm6ds3tr_c_pp_od_t *val)
  2607. {
  2608. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  2609. int32_t ret;
  2610. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  2611. (uint8_t *)&ctrl3_c, 1);
  2612. switch (ctrl3_c.pp_od)
  2613. {
  2614. case LSM6DS3TR_C_PUSH_PULL:
  2615. *val = LSM6DS3TR_C_PUSH_PULL;
  2616. break;
  2617. case LSM6DS3TR_C_OPEN_DRAIN:
  2618. *val = LSM6DS3TR_C_OPEN_DRAIN;
  2619. break;
  2620. default:
  2621. *val = LSM6DS3TR_C_PIN_MODE_ND;
  2622. break;
  2623. }
  2624. return ret;
  2625. }
  2626. /**
  2627. * @brief Interrupt active-high/low.[set]
  2628. *
  2629. * @param ctx Read / write interface definitions
  2630. * @param val Change the values of h_lactive in reg CTRL3_C
  2631. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2632. *
  2633. */
  2634. int32_t lsm6ds3tr_c_pin_polarity_set(const stmdev_ctx_t *ctx,
  2635. lsm6ds3tr_c_h_lactive_t val)
  2636. {
  2637. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  2638. int32_t ret;
  2639. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  2640. (uint8_t *)&ctrl3_c, 1);
  2641. if (ret == 0)
  2642. {
  2643. ctrl3_c.h_lactive = (uint8_t) val;
  2644. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  2645. (uint8_t *)&ctrl3_c, 1);
  2646. }
  2647. return ret;
  2648. }
  2649. /**
  2650. * @brief Interrupt active-high/low.[get]
  2651. *
  2652. * @param ctx Read / write interface definitions
  2653. * @param val Get the values of h_lactive in reg CTRL3_C
  2654. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2655. *
  2656. */
  2657. int32_t lsm6ds3tr_c_pin_polarity_get(const stmdev_ctx_t *ctx,
  2658. lsm6ds3tr_c_h_lactive_t *val)
  2659. {
  2660. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  2661. int32_t ret;
  2662. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  2663. (uint8_t *)&ctrl3_c, 1);
  2664. switch (ctrl3_c.h_lactive)
  2665. {
  2666. case LSM6DS3TR_C_ACTIVE_HIGH:
  2667. *val = LSM6DS3TR_C_ACTIVE_HIGH;
  2668. break;
  2669. case LSM6DS3TR_C_ACTIVE_LOW:
  2670. *val = LSM6DS3TR_C_ACTIVE_LOW;
  2671. break;
  2672. default:
  2673. *val = LSM6DS3TR_C_POLARITY_ND;
  2674. break;
  2675. }
  2676. return ret;
  2677. }
  2678. /**
  2679. * @brief All interrupt signals become available on INT1 pin.[set]
  2680. *
  2681. * @param ctx Read / write interface definitions
  2682. * @param val Change the values of int2_on_int1 in reg CTRL4_C
  2683. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2684. *
  2685. */
  2686. int32_t lsm6ds3tr_c_all_on_int1_set(const stmdev_ctx_t *ctx, uint8_t val)
  2687. {
  2688. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  2689. int32_t ret;
  2690. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2691. (uint8_t *)&ctrl4_c, 1);
  2692. if (ret == 0)
  2693. {
  2694. ctrl4_c.int2_on_int1 = val;
  2695. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2696. (uint8_t *)&ctrl4_c, 1);
  2697. }
  2698. return ret;
  2699. }
  2700. /**
  2701. * @brief All interrupt signals become available on INT1 pin.[get]
  2702. *
  2703. * @param ctx Read / write interface definitions
  2704. * @param val Change the values of int2_on_int1 in reg CTRL4_C
  2705. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2706. *
  2707. */
  2708. int32_t lsm6ds3tr_c_all_on_int1_get(const stmdev_ctx_t *ctx, uint8_t *val)
  2709. {
  2710. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  2711. int32_t ret;
  2712. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2713. (uint8_t *)&ctrl4_c, 1);
  2714. *val = ctrl4_c.int2_on_int1;
  2715. return ret;
  2716. }
  2717. /**
  2718. * @brief Latched/pulsed interrupt.[set]
  2719. *
  2720. * @param ctx Read / write interface definitions
  2721. * @param val Change the values of lir in reg TAP_CFG
  2722. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2723. *
  2724. */
  2725. int32_t lsm6ds3tr_c_int_notification_set(const stmdev_ctx_t *ctx,
  2726. lsm6ds3tr_c_lir_t val)
  2727. {
  2728. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  2729. int32_t ret;
  2730. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  2731. (uint8_t *)&tap_cfg, 1);
  2732. if (ret == 0)
  2733. {
  2734. tap_cfg.lir = (uint8_t) val;
  2735. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  2736. (uint8_t *)&tap_cfg, 1);
  2737. }
  2738. return ret;
  2739. }
  2740. /**
  2741. * @brief Latched/pulsed interrupt.[get]
  2742. *
  2743. * @param ctx Read / write interface definitions
  2744. * @param val Get the values of lir in reg TAP_CFG
  2745. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2746. *
  2747. */
  2748. int32_t lsm6ds3tr_c_int_notification_get(const stmdev_ctx_t *ctx,
  2749. lsm6ds3tr_c_lir_t *val)
  2750. {
  2751. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  2752. int32_t ret;
  2753. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  2754. (uint8_t *)&tap_cfg, 1);
  2755. switch (tap_cfg.lir)
  2756. {
  2757. case LSM6DS3TR_C_INT_PULSED:
  2758. *val = LSM6DS3TR_C_INT_PULSED;
  2759. break;
  2760. case LSM6DS3TR_C_INT_LATCHED:
  2761. *val = LSM6DS3TR_C_INT_LATCHED;
  2762. break;
  2763. default:
  2764. *val = LSM6DS3TR_C_INT_MODE;
  2765. break;
  2766. }
  2767. return ret;
  2768. }
  2769. /**
  2770. * @}
  2771. *
  2772. */
  2773. /**
  2774. * @defgroup LSM6DS3TR_C_Wake_Up_event
  2775. * @brief This section groups all the functions that manage the
  2776. * Wake Up event generation.
  2777. * @{
  2778. *
  2779. */
  2780. /**
  2781. * @brief Threshold for wakeup.1 LSB = FS_XL / 64.[set]
  2782. *
  2783. * @param ctx Read / write interface definitions
  2784. * @param val Change the values of wk_ths in reg WAKE_UP_THS
  2785. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2786. *
  2787. */
  2788. int32_t lsm6ds3tr_c_wkup_threshold_set(const stmdev_ctx_t *ctx, uint8_t val)
  2789. {
  2790. lsm6ds3tr_c_wake_up_ths_t wake_up_ths;
  2791. int32_t ret;
  2792. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_THS,
  2793. (uint8_t *)&wake_up_ths, 1);
  2794. if (ret == 0)
  2795. {
  2796. wake_up_ths.wk_ths = val;
  2797. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_WAKE_UP_THS,
  2798. (uint8_t *)&wake_up_ths, 1);
  2799. }
  2800. return ret;
  2801. }
  2802. /**
  2803. * @brief Threshold for wakeup.1 LSB = FS_XL / 64.[get]
  2804. *
  2805. * @param ctx Read / write interface definitions
  2806. * @param val Change the values of wk_ths in reg WAKE_UP_THS
  2807. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2808. *
  2809. */
  2810. int32_t lsm6ds3tr_c_wkup_threshold_get(const stmdev_ctx_t *ctx,
  2811. uint8_t *val)
  2812. {
  2813. lsm6ds3tr_c_wake_up_ths_t wake_up_ths;
  2814. int32_t ret;
  2815. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_THS,
  2816. (uint8_t *)&wake_up_ths, 1);
  2817. *val = wake_up_ths.wk_ths;
  2818. return ret;
  2819. }
  2820. /**
  2821. * @brief Wake up duration event.1LSb = 1 / ODR[set]
  2822. *
  2823. * @param ctx Read / write interface definitions
  2824. * @param val Change the values of wake_dur in reg WAKE_UP_DUR
  2825. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2826. *
  2827. */
  2828. int32_t lsm6ds3tr_c_wkup_dur_set(const stmdev_ctx_t *ctx, uint8_t val)
  2829. {
  2830. lsm6ds3tr_c_wake_up_dur_t wake_up_dur;
  2831. int32_t ret;
  2832. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  2833. (uint8_t *)&wake_up_dur, 1);
  2834. if (ret == 0)
  2835. {
  2836. wake_up_dur.wake_dur = val;
  2837. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  2838. (uint8_t *)&wake_up_dur, 1);
  2839. }
  2840. return ret;
  2841. }
  2842. /**
  2843. * @brief Wake up duration event.1LSb = 1 / ODR[get]
  2844. *
  2845. * @param ctx Read / write interface definitions
  2846. * @param val Change the values of wake_dur in reg WAKE_UP_DUR
  2847. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2848. *
  2849. */
  2850. int32_t lsm6ds3tr_c_wkup_dur_get(const stmdev_ctx_t *ctx, uint8_t *val)
  2851. {
  2852. lsm6ds3tr_c_wake_up_dur_t wake_up_dur;
  2853. int32_t ret;
  2854. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  2855. (uint8_t *)&wake_up_dur, 1);
  2856. *val = wake_up_dur.wake_dur;
  2857. return ret;
  2858. }
  2859. /**
  2860. * @}
  2861. *
  2862. */
  2863. /**
  2864. * @defgroup LSM6DS3TR_C_Activity/Inactivity_detection
  2865. * @brief This section groups all the functions concerning
  2866. * activity/inactivity detection.
  2867. * @{
  2868. *
  2869. */
  2870. /**
  2871. * @brief Enables gyroscope Sleep mode.[set]
  2872. *
  2873. * @param ctx Read / write interface definitions
  2874. * @param val Change the values of sleep in reg CTRL4_C
  2875. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2876. *
  2877. */
  2878. int32_t lsm6ds3tr_c_gy_sleep_mode_set(const stmdev_ctx_t *ctx, uint8_t val)
  2879. {
  2880. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  2881. int32_t ret;
  2882. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2883. (uint8_t *)&ctrl4_c, 1);
  2884. if (ret == 0)
  2885. {
  2886. ctrl4_c.sleep = val;
  2887. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2888. (uint8_t *)&ctrl4_c, 1);
  2889. }
  2890. return ret;
  2891. }
  2892. /**
  2893. * @brief Enables gyroscope Sleep mode.[get]
  2894. *
  2895. * @param ctx Read / write interface definitions
  2896. * @param val Change the values of sleep in reg CTRL4_C
  2897. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2898. *
  2899. */
  2900. int32_t lsm6ds3tr_c_gy_sleep_mode_get(const stmdev_ctx_t *ctx, uint8_t *val)
  2901. {
  2902. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  2903. int32_t ret;
  2904. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2905. (uint8_t *)&ctrl4_c, 1);
  2906. *val = ctrl4_c.sleep;
  2907. return ret;
  2908. }
  2909. /**
  2910. * @brief Enable inactivity function.[set]
  2911. *
  2912. * @param ctx Read / write interface definitions
  2913. * @param val Change the values of inact_en in reg TAP_CFG
  2914. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2915. *
  2916. */
  2917. int32_t lsm6ds3tr_c_act_mode_set(const stmdev_ctx_t *ctx,
  2918. lsm6ds3tr_c_inact_en_t val)
  2919. {
  2920. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  2921. int32_t ret;
  2922. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  2923. (uint8_t *)&tap_cfg, 1);
  2924. if (ret == 0)
  2925. {
  2926. tap_cfg.inact_en = (uint8_t) val;
  2927. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  2928. (uint8_t *)&tap_cfg, 1);
  2929. }
  2930. return ret;
  2931. }
  2932. /**
  2933. * @brief Enable inactivity function.[get]
  2934. *
  2935. * @param ctx Read / write interface definitions
  2936. * @param val Get the values of inact_en in reg TAP_CFG
  2937. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2938. *
  2939. */
  2940. int32_t lsm6ds3tr_c_act_mode_get(const stmdev_ctx_t *ctx,
  2941. lsm6ds3tr_c_inact_en_t *val)
  2942. {
  2943. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  2944. int32_t ret;
  2945. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  2946. (uint8_t *)&tap_cfg, 1);
  2947. switch (tap_cfg.inact_en)
  2948. {
  2949. case LSM6DS3TR_C_PROPERTY_DISABLE:
  2950. *val = LSM6DS3TR_C_PROPERTY_DISABLE;
  2951. break;
  2952. case LSM6DS3TR_C_XL_12Hz5_GY_NOT_AFFECTED:
  2953. *val = LSM6DS3TR_C_XL_12Hz5_GY_NOT_AFFECTED;
  2954. break;
  2955. case LSM6DS3TR_C_XL_12Hz5_GY_SLEEP:
  2956. *val = LSM6DS3TR_C_XL_12Hz5_GY_SLEEP;
  2957. break;
  2958. case LSM6DS3TR_C_XL_12Hz5_GY_PD:
  2959. *val = LSM6DS3TR_C_XL_12Hz5_GY_PD;
  2960. break;
  2961. default:
  2962. *val = LSM6DS3TR_C_ACT_MODE_ND;
  2963. break;
  2964. }
  2965. return ret;
  2966. }
  2967. /**
  2968. * @brief Duration to go in sleep mode.1 LSb = 512 / ODR[set]
  2969. *
  2970. * @param ctx Read / write interface definitions
  2971. * @param val Change the values of sleep_dur in reg WAKE_UP_DUR
  2972. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2973. *
  2974. */
  2975. int32_t lsm6ds3tr_c_act_sleep_dur_set(const stmdev_ctx_t *ctx, uint8_t val)
  2976. {
  2977. lsm6ds3tr_c_wake_up_dur_t wake_up_dur;
  2978. int32_t ret;
  2979. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  2980. (uint8_t *)&wake_up_dur, 1);
  2981. if (ret == 0)
  2982. {
  2983. wake_up_dur.sleep_dur = val;
  2984. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  2985. (uint8_t *)&wake_up_dur, 1);
  2986. }
  2987. return ret;
  2988. }
  2989. /**
  2990. * @brief Duration to go in sleep mode. 1 LSb = 512 / ODR[get]
  2991. *
  2992. * @param ctx Read / write interface definitions
  2993. * @param val Change the values of sleep_dur in reg WAKE_UP_DUR
  2994. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2995. *
  2996. */
  2997. int32_t lsm6ds3tr_c_act_sleep_dur_get(const stmdev_ctx_t *ctx, uint8_t *val)
  2998. {
  2999. lsm6ds3tr_c_wake_up_dur_t wake_up_dur;
  3000. int32_t ret;
  3001. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  3002. (uint8_t *)&wake_up_dur, 1);
  3003. *val = wake_up_dur.sleep_dur;
  3004. return ret;
  3005. }
  3006. /**
  3007. * @}
  3008. *
  3009. */
  3010. /**
  3011. * @defgroup LSM6DS3TR_C_tap_generator
  3012. * @brief This section groups all the functions that manage the
  3013. * tap and double tap event generation.
  3014. * @{
  3015. *
  3016. */
  3017. /**
  3018. * @brief Read the tap / double tap source register.[get]
  3019. *
  3020. * @param ctx Read / write interface definitions
  3021. * @param val Structure of registers from TAP_SRC
  3022. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3023. *
  3024. */
  3025. int32_t lsm6ds3tr_c_tap_src_get(const stmdev_ctx_t *ctx,
  3026. lsm6ds3tr_c_tap_src_t *val)
  3027. {
  3028. int32_t ret;
  3029. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_SRC, (uint8_t *) val, 1);
  3030. return ret;
  3031. }
  3032. /**
  3033. * @brief Enable Z direction in tap recognition.[set]
  3034. *
  3035. * @param ctx Read / write interface definitions
  3036. * @param val Change the values of tap_z_en in reg TAP_CFG
  3037. *
  3038. */
  3039. int32_t lsm6ds3tr_c_tap_detection_on_z_set(const stmdev_ctx_t *ctx,
  3040. uint8_t val)
  3041. {
  3042. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  3043. int32_t ret;
  3044. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  3045. (uint8_t *)&tap_cfg, 1);
  3046. if (ret == 0)
  3047. {
  3048. tap_cfg.tap_z_en = val;
  3049. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  3050. (uint8_t *)&tap_cfg, 1);
  3051. }
  3052. return ret;
  3053. }
  3054. /**
  3055. * @brief Enable Z direction in tap recognition.[get]
  3056. *
  3057. * @param ctx Read / write interface definitions
  3058. * @param val Change the values of tap_z_en in reg TAP_CFG
  3059. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3060. *
  3061. */
  3062. int32_t lsm6ds3tr_c_tap_detection_on_z_get(const stmdev_ctx_t *ctx,
  3063. uint8_t *val)
  3064. {
  3065. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  3066. int32_t ret;
  3067. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  3068. (uint8_t *)&tap_cfg, 1);
  3069. *val = tap_cfg.tap_z_en;
  3070. return ret;
  3071. }
  3072. /**
  3073. * @brief Enable Y direction in tap recognition.[set]
  3074. *
  3075. * @param ctx Read / write interface definitions
  3076. * @param val Change the values of tap_y_en in reg TAP_CFG
  3077. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3078. *
  3079. */
  3080. int32_t lsm6ds3tr_c_tap_detection_on_y_set(const stmdev_ctx_t *ctx,
  3081. uint8_t val)
  3082. {
  3083. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  3084. int32_t ret;
  3085. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  3086. (uint8_t *)&tap_cfg, 1);
  3087. if (ret == 0)
  3088. {
  3089. tap_cfg.tap_y_en = val;
  3090. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  3091. (uint8_t *)&tap_cfg, 1);
  3092. }
  3093. return ret;
  3094. }
  3095. /**
  3096. * @brief Enable Y direction in tap recognition.[get]
  3097. *
  3098. * @param ctx Read / write interface definitions
  3099. * @param val Change the values of tap_y_en in reg TAP_CFG
  3100. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3101. *
  3102. */
  3103. int32_t lsm6ds3tr_c_tap_detection_on_y_get(const stmdev_ctx_t *ctx,
  3104. uint8_t *val)
  3105. {
  3106. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  3107. int32_t ret;
  3108. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  3109. (uint8_t *)&tap_cfg, 1);
  3110. *val = tap_cfg.tap_y_en;
  3111. return ret;
  3112. }
  3113. /**
  3114. * @brief Enable X direction in tap recognition.[set]
  3115. *
  3116. * @param ctx Read / write interface definitions
  3117. * @param val Change the values of tap_x_en in reg TAP_CFG
  3118. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3119. *
  3120. */
  3121. int32_t lsm6ds3tr_c_tap_detection_on_x_set(const stmdev_ctx_t *ctx,
  3122. uint8_t val)
  3123. {
  3124. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  3125. int32_t ret;
  3126. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  3127. (uint8_t *)&tap_cfg, 1);
  3128. if (ret == 0)
  3129. {
  3130. tap_cfg.tap_x_en = val;
  3131. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  3132. (uint8_t *)&tap_cfg, 1);
  3133. }
  3134. return ret;
  3135. }
  3136. /**
  3137. * @brief Enable X direction in tap recognition.[get]
  3138. *
  3139. * @param ctx Read / write interface definitions
  3140. * @param val Change the values of tap_x_en in reg TAP_CFG
  3141. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3142. *
  3143. */
  3144. int32_t lsm6ds3tr_c_tap_detection_on_x_get(const stmdev_ctx_t *ctx,
  3145. uint8_t *val)
  3146. {
  3147. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  3148. int32_t ret;
  3149. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  3150. (uint8_t *)&tap_cfg, 1);
  3151. *val = tap_cfg.tap_x_en;
  3152. return ret;
  3153. }
  3154. /**
  3155. * @brief Threshold for tap recognition.[set]
  3156. *
  3157. * @param ctx Read / write interface definitions
  3158. * @param val Change the values of tap_ths in reg TAP_THS_6D
  3159. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3160. *
  3161. */
  3162. int32_t lsm6ds3tr_c_tap_threshold_x_set(const stmdev_ctx_t *ctx,
  3163. uint8_t val)
  3164. {
  3165. lsm6ds3tr_c_tap_ths_6d_t tap_ths_6d;
  3166. int32_t ret;
  3167. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_THS_6D,
  3168. (uint8_t *)&tap_ths_6d, 1);
  3169. if (ret == 0)
  3170. {
  3171. tap_ths_6d.tap_ths = val;
  3172. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_TAP_THS_6D,
  3173. (uint8_t *)&tap_ths_6d, 1);
  3174. }
  3175. return ret;
  3176. }
  3177. /**
  3178. * @brief Threshold for tap recognition.[get]
  3179. *
  3180. * @param ctx Read / write interface definitions
  3181. * @param val Change the values of tap_ths in reg TAP_THS_6D
  3182. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3183. *
  3184. */
  3185. int32_t lsm6ds3tr_c_tap_threshold_x_get(const stmdev_ctx_t *ctx,
  3186. uint8_t *val)
  3187. {
  3188. lsm6ds3tr_c_tap_ths_6d_t tap_ths_6d;
  3189. int32_t ret;
  3190. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_THS_6D,
  3191. (uint8_t *)&tap_ths_6d, 1);
  3192. *val = tap_ths_6d.tap_ths;
  3193. return ret;
  3194. }
  3195. /**
  3196. * @brief Maximum duration is the maximum time of an overthreshold signal
  3197. * detection to be recognized as a tap event.
  3198. * The default value of these bits is 00b which corresponds to
  3199. * 4*ODR_XL time.
  3200. * If the SHOCK[1:0] bits are set to a different
  3201. * value, 1LSB corresponds to 8*ODR_XL time.[set]
  3202. *
  3203. * @param ctx Read / write interface definitions
  3204. * @param val Change the values of shock in reg INT_DUR2
  3205. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3206. *
  3207. */
  3208. int32_t lsm6ds3tr_c_tap_shock_set(const stmdev_ctx_t *ctx, uint8_t val)
  3209. {
  3210. lsm6ds3tr_c_int_dur2_t int_dur2;
  3211. int32_t ret;
  3212. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_INT_DUR2,
  3213. (uint8_t *)&int_dur2, 1);
  3214. if (ret == 0)
  3215. {
  3216. int_dur2.shock = val;
  3217. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_INT_DUR2,
  3218. (uint8_t *)&int_dur2, 1);
  3219. }
  3220. return ret;
  3221. }
  3222. /**
  3223. * @brief Maximum duration is the maximum time of an overthreshold signal
  3224. * detection to be recognized as a tap event.
  3225. * The default value of these bits is 00b which corresponds to
  3226. * 4*ODR_XL time.
  3227. * If the SHOCK[1:0] bits are set to a different value, 1LSB
  3228. * corresponds to 8*ODR_XL time.[get]
  3229. *
  3230. * @param ctx Read / write interface definitions
  3231. * @param val Change the values of shock in reg INT_DUR2
  3232. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3233. *
  3234. */
  3235. int32_t lsm6ds3tr_c_tap_shock_get(const stmdev_ctx_t *ctx, uint8_t *val)
  3236. {
  3237. lsm6ds3tr_c_int_dur2_t int_dur2;
  3238. int32_t ret;
  3239. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_INT_DUR2,
  3240. (uint8_t *)&int_dur2, 1);
  3241. *val = int_dur2.shock;
  3242. return ret;
  3243. }
  3244. /**
  3245. * @brief Quiet time is the time after the first detected tap in which there
  3246. * must not be any overthreshold event.
  3247. * The default value of these bits is 00b which corresponds to
  3248. * 2*ODR_XL time.
  3249. * If the QUIET[1:0] bits are set to a different value, 1LSB
  3250. * corresponds to 4*ODR_XL time.[set]
  3251. *
  3252. * @param ctx Read / write interface definitions
  3253. * @param val Change the values of quiet in reg INT_DUR2
  3254. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3255. *
  3256. */
  3257. int32_t lsm6ds3tr_c_tap_quiet_set(const stmdev_ctx_t *ctx, uint8_t val)
  3258. {
  3259. lsm6ds3tr_c_int_dur2_t int_dur2;
  3260. int32_t ret;
  3261. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_INT_DUR2,
  3262. (uint8_t *)&int_dur2, 1);
  3263. if (ret == 0)
  3264. {
  3265. int_dur2.quiet = val;
  3266. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_INT_DUR2,
  3267. (uint8_t *)&int_dur2, 1);
  3268. }
  3269. return ret;
  3270. }
  3271. /**
  3272. * @brief Quiet time is the time after the first detected tap in which there
  3273. * must not be any overthreshold event.
  3274. * The default value of these bits is 00b which corresponds to
  3275. * 2*ODR_XL time.
  3276. * If the QUIET[1:0] bits are set to a different value, 1LSB
  3277. * corresponds to 4*ODR_XL time.[get]
  3278. *
  3279. * @param ctx Read / write interface definitions
  3280. * @param val Change the values of quiet in reg INT_DUR2
  3281. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3282. *
  3283. */
  3284. int32_t lsm6ds3tr_c_tap_quiet_get(const stmdev_ctx_t *ctx, uint8_t *val)
  3285. {
  3286. lsm6ds3tr_c_int_dur2_t int_dur2;
  3287. int32_t ret;
  3288. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_INT_DUR2,
  3289. (uint8_t *)&int_dur2, 1);
  3290. *val = int_dur2.quiet;
  3291. return ret;
  3292. }
  3293. /**
  3294. * @brief When double tap recognition is enabled, this register expresses the
  3295. * maximum time between two consecutive detected taps to determine a
  3296. * double tap event.
  3297. * The default value of these bits is 0000b which corresponds to
  3298. * 16*ODR_XL time.
  3299. * If the DUR[3:0] bits are set to a different value,1LSB corresponds
  3300. * to 32*ODR_XL time.[set]
  3301. *
  3302. * @param ctx Read / write interface definitions
  3303. * @param val Change the values of dur in reg INT_DUR2
  3304. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3305. *
  3306. */
  3307. int32_t lsm6ds3tr_c_tap_dur_set(const stmdev_ctx_t *ctx, uint8_t val)
  3308. {
  3309. lsm6ds3tr_c_int_dur2_t int_dur2;
  3310. int32_t ret;
  3311. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_INT_DUR2,
  3312. (uint8_t *)&int_dur2, 1);
  3313. if (ret == 0)
  3314. {
  3315. int_dur2.dur = val;
  3316. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_INT_DUR2,
  3317. (uint8_t *)&int_dur2, 1);
  3318. }
  3319. return ret;
  3320. }
  3321. /**
  3322. * @brief When double tap recognition is enabled, this register expresses the
  3323. * maximum time between two consecutive detected taps to determine a
  3324. * double tap event.
  3325. * The default value of these bits is 0000b which corresponds to
  3326. * 16*ODR_XL time.
  3327. * If the DUR[3:0] bits are set to a different value,1LSB corresponds
  3328. * to 32*ODR_XL time.[get]
  3329. *
  3330. * @param ctx Read / write interface definitions
  3331. * @param val Change the values of dur in reg INT_DUR2
  3332. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3333. *
  3334. */
  3335. int32_t lsm6ds3tr_c_tap_dur_get(const stmdev_ctx_t *ctx, uint8_t *val)
  3336. {
  3337. lsm6ds3tr_c_int_dur2_t int_dur2;
  3338. int32_t ret;
  3339. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_INT_DUR2,
  3340. (uint8_t *)&int_dur2, 1);
  3341. *val = int_dur2.dur;
  3342. return ret;
  3343. }
  3344. /**
  3345. * @brief Single/double-tap event enable/disable.[set]
  3346. *
  3347. * @param ctx Read / write interface definitions
  3348. * @param val Change the values of
  3349. * single_double_tap in reg WAKE_UP_THS
  3350. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3351. *
  3352. */
  3353. int32_t lsm6ds3tr_c_tap_mode_set(const stmdev_ctx_t *ctx,
  3354. lsm6ds3tr_c_single_double_tap_t val)
  3355. {
  3356. lsm6ds3tr_c_wake_up_ths_t wake_up_ths;
  3357. int32_t ret;
  3358. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_THS,
  3359. (uint8_t *)&wake_up_ths, 1);
  3360. if (ret == 0)
  3361. {
  3362. wake_up_ths.single_double_tap = (uint8_t) val;
  3363. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_WAKE_UP_THS,
  3364. (uint8_t *)&wake_up_ths, 1);
  3365. }
  3366. return ret;
  3367. }
  3368. /**
  3369. * @brief Single/double-tap event enable/disable.[get]
  3370. *
  3371. * @param ctx Read / write interface definitions
  3372. * @param val Get the values of single_double_tap
  3373. * in reg WAKE_UP_THS
  3374. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3375. *
  3376. */
  3377. int32_t lsm6ds3tr_c_tap_mode_get(const stmdev_ctx_t *ctx,
  3378. lsm6ds3tr_c_single_double_tap_t *val)
  3379. {
  3380. lsm6ds3tr_c_wake_up_ths_t wake_up_ths;
  3381. int32_t ret;
  3382. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_THS,
  3383. (uint8_t *)&wake_up_ths, 1);
  3384. switch (wake_up_ths.single_double_tap)
  3385. {
  3386. case LSM6DS3TR_C_ONLY_SINGLE:
  3387. *val = LSM6DS3TR_C_ONLY_SINGLE;
  3388. break;
  3389. case LSM6DS3TR_C_BOTH_SINGLE_DOUBLE:
  3390. *val = LSM6DS3TR_C_BOTH_SINGLE_DOUBLE;
  3391. break;
  3392. default:
  3393. *val = LSM6DS3TR_C_TAP_MODE_ND;
  3394. break;
  3395. }
  3396. return ret;
  3397. }
  3398. /**
  3399. * @}
  3400. *
  3401. */
  3402. /**
  3403. * @defgroup LSM6DS3TR_C_ Six_position_detection(6D/4D)
  3404. * @brief This section groups all the functions concerning six
  3405. * position detection (6D).
  3406. * @{
  3407. *
  3408. */
  3409. /**
  3410. * @brief LPF2 feed 6D function selection.[set]
  3411. *
  3412. * @param ctx Read / write interface definitions
  3413. * @param val Change the values of low_pass_on_6d in
  3414. * reg CTRL8_XL
  3415. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3416. *
  3417. */
  3418. int32_t lsm6ds3tr_c_6d_feed_data_set(const stmdev_ctx_t *ctx,
  3419. lsm6ds3tr_c_low_pass_on_6d_t val)
  3420. {
  3421. lsm6ds3tr_c_ctrl8_xl_t ctrl8_xl;
  3422. int32_t ret;
  3423. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  3424. (uint8_t *)&ctrl8_xl, 1);
  3425. if (ret == 0)
  3426. {
  3427. ctrl8_xl.low_pass_on_6d = (uint8_t) val;
  3428. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  3429. (uint8_t *)&ctrl8_xl, 1);
  3430. }
  3431. return ret;
  3432. }
  3433. /**
  3434. * @brief LPF2 feed 6D function selection.[get]
  3435. *
  3436. * @param ctx Read / write interface definitions
  3437. * @param val Get the values of low_pass_on_6d in reg CTRL8_XL
  3438. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3439. *
  3440. */
  3441. int32_t lsm6ds3tr_c_6d_feed_data_get(const stmdev_ctx_t *ctx,
  3442. lsm6ds3tr_c_low_pass_on_6d_t *val)
  3443. {
  3444. lsm6ds3tr_c_ctrl8_xl_t ctrl8_xl;
  3445. int32_t ret;
  3446. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  3447. (uint8_t *)&ctrl8_xl, 1);
  3448. switch (ctrl8_xl.low_pass_on_6d)
  3449. {
  3450. case LSM6DS3TR_C_ODR_DIV_2_FEED:
  3451. *val = LSM6DS3TR_C_ODR_DIV_2_FEED;
  3452. break;
  3453. case LSM6DS3TR_C_LPF2_FEED:
  3454. *val = LSM6DS3TR_C_LPF2_FEED;
  3455. break;
  3456. default:
  3457. *val = LSM6DS3TR_C_6D_FEED_ND;
  3458. break;
  3459. }
  3460. return ret;
  3461. }
  3462. /**
  3463. * @brief Threshold for 4D/6D function.[set]
  3464. *
  3465. * @param ctx Read / write interface definitions
  3466. * @param val Change the values of sixd_ths in reg TAP_THS_6D
  3467. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3468. *
  3469. */
  3470. int32_t lsm6ds3tr_c_6d_threshold_set(const stmdev_ctx_t *ctx,
  3471. lsm6ds3tr_c_sixd_ths_t val)
  3472. {
  3473. lsm6ds3tr_c_tap_ths_6d_t tap_ths_6d;
  3474. int32_t ret;
  3475. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_THS_6D,
  3476. (uint8_t *)&tap_ths_6d, 1);
  3477. if (ret == 0)
  3478. {
  3479. tap_ths_6d.sixd_ths = (uint8_t) val;
  3480. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_TAP_THS_6D,
  3481. (uint8_t *)&tap_ths_6d, 1);
  3482. }
  3483. return ret;
  3484. }
  3485. /**
  3486. * @brief Threshold for 4D/6D function.[get]
  3487. *
  3488. * @param ctx Read / write interface definitions
  3489. * @param val Get the values of sixd_ths in reg TAP_THS_6D
  3490. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3491. *
  3492. */
  3493. int32_t lsm6ds3tr_c_6d_threshold_get(const stmdev_ctx_t *ctx,
  3494. lsm6ds3tr_c_sixd_ths_t *val)
  3495. {
  3496. lsm6ds3tr_c_tap_ths_6d_t tap_ths_6d;
  3497. int32_t ret;
  3498. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_THS_6D,
  3499. (uint8_t *)&tap_ths_6d, 1);
  3500. switch (tap_ths_6d.sixd_ths)
  3501. {
  3502. case LSM6DS3TR_C_DEG_80:
  3503. *val = LSM6DS3TR_C_DEG_80;
  3504. break;
  3505. case LSM6DS3TR_C_DEG_70:
  3506. *val = LSM6DS3TR_C_DEG_70;
  3507. break;
  3508. case LSM6DS3TR_C_DEG_60:
  3509. *val = LSM6DS3TR_C_DEG_60;
  3510. break;
  3511. case LSM6DS3TR_C_DEG_50:
  3512. *val = LSM6DS3TR_C_DEG_50;
  3513. break;
  3514. default:
  3515. *val = LSM6DS3TR_C_6D_TH_ND;
  3516. break;
  3517. }
  3518. return ret;
  3519. }
  3520. /**
  3521. * @brief 4D orientation detection enable.[set]
  3522. *
  3523. * @param ctx Read / write interface definitions
  3524. * @param val Change the values of d4d_en in reg TAP_THS_6D
  3525. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3526. *
  3527. */
  3528. int32_t lsm6ds3tr_c_4d_mode_set(const stmdev_ctx_t *ctx, uint8_t val)
  3529. {
  3530. lsm6ds3tr_c_tap_ths_6d_t tap_ths_6d;
  3531. int32_t ret;
  3532. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_THS_6D,
  3533. (uint8_t *)&tap_ths_6d, 1);
  3534. if (ret == 0)
  3535. {
  3536. tap_ths_6d.d4d_en = val;
  3537. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_TAP_THS_6D,
  3538. (uint8_t *)&tap_ths_6d, 1);
  3539. }
  3540. return ret;
  3541. }
  3542. /**
  3543. * @brief 4D orientation detection enable.[get]
  3544. *
  3545. * @param ctx Read / write interface definitions
  3546. * @param val Change the values of d4d_en in reg TAP_THS_6D
  3547. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3548. *
  3549. */
  3550. int32_t lsm6ds3tr_c_4d_mode_get(const stmdev_ctx_t *ctx, uint8_t *val)
  3551. {
  3552. lsm6ds3tr_c_tap_ths_6d_t tap_ths_6d;
  3553. int32_t ret;
  3554. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_THS_6D,
  3555. (uint8_t *)&tap_ths_6d, 1);
  3556. *val = tap_ths_6d.d4d_en;
  3557. return ret;
  3558. }
  3559. /**
  3560. * @}
  3561. *
  3562. */
  3563. /**
  3564. * @defgroup LSM6DS3TR_C_free_fall
  3565. * @brief This section group all the functions concerning the free
  3566. * fall detection.
  3567. * @{
  3568. *
  3569. */
  3570. /**
  3571. * @brief Free-fall duration event. 1LSb = 1 / ODR[set]
  3572. *
  3573. * @param ctx Read / write interface definitions
  3574. * @param val Change the values of ff_dur in reg WAKE_UP_DUR
  3575. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3576. *
  3577. */
  3578. int32_t lsm6ds3tr_c_ff_dur_set(const stmdev_ctx_t *ctx, uint8_t val)
  3579. {
  3580. lsm6ds3tr_c_wake_up_dur_t wake_up_dur;
  3581. lsm6ds3tr_c_free_fall_t free_fall;
  3582. int32_t ret;
  3583. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FREE_FALL,
  3584. (uint8_t *)&free_fall, 1);
  3585. if (ret == 0)
  3586. {
  3587. free_fall.ff_dur = (val & 0x1FU);
  3588. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FREE_FALL,
  3589. (uint8_t *)&free_fall, 1);
  3590. if (ret == 0)
  3591. {
  3592. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  3593. (uint8_t *)&wake_up_dur, 1);
  3594. if (ret == 0)
  3595. {
  3596. wake_up_dur.ff_dur = (val & 0x20U) >> 5;
  3597. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  3598. (uint8_t *)&wake_up_dur, 1);
  3599. }
  3600. }
  3601. }
  3602. return ret;
  3603. }
  3604. /**
  3605. * @brief Free-fall duration event. 1LSb = 1 / ODR[get]
  3606. *
  3607. * @param ctx Read / write interface definitions
  3608. * @param val Change the values of ff_dur in reg WAKE_UP_DUR
  3609. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3610. *
  3611. */
  3612. int32_t lsm6ds3tr_c_ff_dur_get(const stmdev_ctx_t *ctx, uint8_t *val)
  3613. {
  3614. lsm6ds3tr_c_wake_up_dur_t wake_up_dur;
  3615. lsm6ds3tr_c_free_fall_t free_fall;
  3616. int32_t ret;
  3617. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  3618. (uint8_t *)&wake_up_dur, 1);
  3619. if (ret == 0)
  3620. {
  3621. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FREE_FALL,
  3622. (uint8_t *)&free_fall, 1);
  3623. }
  3624. *val = (wake_up_dur.ff_dur << 5) + free_fall.ff_dur;
  3625. return ret;
  3626. }
  3627. /**
  3628. * @brief Free fall threshold setting.[set]
  3629. *
  3630. * @param ctx Read / write interface definitions
  3631. * @param val Change the values of ff_ths in reg FREE_FALL
  3632. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3633. *
  3634. */
  3635. int32_t lsm6ds3tr_c_ff_threshold_set(const stmdev_ctx_t *ctx,
  3636. lsm6ds3tr_c_ff_ths_t val)
  3637. {
  3638. lsm6ds3tr_c_free_fall_t free_fall;
  3639. int32_t ret;
  3640. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FREE_FALL,
  3641. (uint8_t *)&free_fall, 1);
  3642. if (ret == 0)
  3643. {
  3644. free_fall.ff_ths = (uint8_t) val;
  3645. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FREE_FALL,
  3646. (uint8_t *)&free_fall, 1);
  3647. }
  3648. return ret;
  3649. }
  3650. /**
  3651. * @brief Free fall threshold setting.[get]
  3652. *
  3653. * @param ctx Read / write interface definitions
  3654. * @param val Get the values of ff_ths in reg FREE_FALL
  3655. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3656. *
  3657. */
  3658. int32_t lsm6ds3tr_c_ff_threshold_get(const stmdev_ctx_t *ctx,
  3659. lsm6ds3tr_c_ff_ths_t *val)
  3660. {
  3661. lsm6ds3tr_c_free_fall_t free_fall;
  3662. int32_t ret;
  3663. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FREE_FALL,
  3664. (uint8_t *)&free_fall, 1);
  3665. switch (free_fall.ff_ths)
  3666. {
  3667. case LSM6DS3TR_C_FF_TSH_156mg:
  3668. *val = LSM6DS3TR_C_FF_TSH_156mg;
  3669. break;
  3670. case LSM6DS3TR_C_FF_TSH_219mg:
  3671. *val = LSM6DS3TR_C_FF_TSH_219mg;
  3672. break;
  3673. case LSM6DS3TR_C_FF_TSH_250mg:
  3674. *val = LSM6DS3TR_C_FF_TSH_250mg;
  3675. break;
  3676. case LSM6DS3TR_C_FF_TSH_312mg:
  3677. *val = LSM6DS3TR_C_FF_TSH_312mg;
  3678. break;
  3679. case LSM6DS3TR_C_FF_TSH_344mg:
  3680. *val = LSM6DS3TR_C_FF_TSH_344mg;
  3681. break;
  3682. case LSM6DS3TR_C_FF_TSH_406mg:
  3683. *val = LSM6DS3TR_C_FF_TSH_406mg;
  3684. break;
  3685. case LSM6DS3TR_C_FF_TSH_469mg:
  3686. *val = LSM6DS3TR_C_FF_TSH_469mg;
  3687. break;
  3688. case LSM6DS3TR_C_FF_TSH_500mg:
  3689. *val = LSM6DS3TR_C_FF_TSH_500mg;
  3690. break;
  3691. default:
  3692. *val = LSM6DS3TR_C_FF_TSH_ND;
  3693. break;
  3694. }
  3695. return ret;
  3696. }
  3697. /**
  3698. * @}
  3699. *
  3700. */
  3701. /**
  3702. * @defgroup LSM6DS3TR_C_fifo
  3703. * @brief This section group all the functions concerning the
  3704. * fifo usage
  3705. * @{
  3706. *
  3707. */
  3708. /**
  3709. * @brief FIFO watermark level selection.[set]
  3710. *
  3711. * @param ctx Read / write interface definitions
  3712. * @param val Change the values of fth in reg FIFO_CTRL1
  3713. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3714. *
  3715. */
  3716. int32_t lsm6ds3tr_c_fifo_watermark_set(const stmdev_ctx_t *ctx,
  3717. uint16_t val)
  3718. {
  3719. lsm6ds3tr_c_fifo_ctrl1_t fifo_ctrl1;
  3720. lsm6ds3tr_c_fifo_ctrl2_t fifo_ctrl2;
  3721. int32_t ret;
  3722. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3723. (uint8_t *)&fifo_ctrl2, 1);
  3724. if (ret == 0)
  3725. {
  3726. fifo_ctrl1.fth = (uint8_t)(0x00FFU & val);
  3727. fifo_ctrl2.fth = (uint8_t)((0x0700U & val) >> 8);
  3728. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL1,
  3729. (uint8_t *)&fifo_ctrl1, 1);
  3730. if (ret == 0)
  3731. {
  3732. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3733. (uint8_t *)&fifo_ctrl2, 1);
  3734. }
  3735. }
  3736. return ret;
  3737. }
  3738. /**
  3739. * @brief FIFO watermark level selection.[get]
  3740. *
  3741. * @param ctx Read / write interface definitions
  3742. * @param val Change the values of fth in reg FIFO_CTRL1
  3743. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3744. *
  3745. */
  3746. int32_t lsm6ds3tr_c_fifo_watermark_get(const stmdev_ctx_t *ctx,
  3747. uint16_t *val)
  3748. {
  3749. lsm6ds3tr_c_fifo_ctrl1_t fifo_ctrl1;
  3750. lsm6ds3tr_c_fifo_ctrl2_t fifo_ctrl2;
  3751. int32_t ret;
  3752. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL1,
  3753. (uint8_t *)&fifo_ctrl1, 1);
  3754. if (ret == 0)
  3755. {
  3756. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3757. (uint8_t *)&fifo_ctrl2, 1);
  3758. }
  3759. *val = ((uint16_t)fifo_ctrl2.fth << 8) + (uint16_t)fifo_ctrl1.fth;
  3760. return ret;
  3761. }
  3762. /**
  3763. * @brief FIFO data level.[get]
  3764. *
  3765. * @param ctx Read / write interface definitions
  3766. * @param val get the values of diff_fifo in reg FIFO_STATUS1 and
  3767. * FIFO_STATUS2(diff_fifo), it is recommended to set the
  3768. * BDU bit.
  3769. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3770. *
  3771. */
  3772. int32_t lsm6ds3tr_c_fifo_data_level_get(const stmdev_ctx_t *ctx,
  3773. uint16_t *val)
  3774. {
  3775. lsm6ds3tr_c_fifo_status1_t fifo_status1;
  3776. lsm6ds3tr_c_fifo_status2_t fifo_status2;
  3777. int32_t ret;
  3778. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_STATUS1,
  3779. (uint8_t *)&fifo_status1, 1);
  3780. if (ret == 0)
  3781. {
  3782. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_STATUS2,
  3783. (uint8_t *)&fifo_status2, 1);
  3784. *val = ((uint16_t) fifo_status2.diff_fifo << 8) +
  3785. (uint16_t) fifo_status1.diff_fifo;
  3786. }
  3787. return ret;
  3788. }
  3789. /**
  3790. * @brief FIFO watermark.[get]
  3791. *
  3792. * @param ctx Read / write interface definitions
  3793. * @param val get the values of watermark in reg FIFO_STATUS2 and
  3794. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3795. *
  3796. */
  3797. int32_t lsm6ds3tr_c_fifo_wtm_flag_get(const stmdev_ctx_t *ctx, uint8_t *val)
  3798. {
  3799. lsm6ds3tr_c_fifo_status2_t fifo_status2;
  3800. int32_t ret;
  3801. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_STATUS2,
  3802. (uint8_t *)&fifo_status2, 1);
  3803. *val = fifo_status2.waterm;
  3804. return ret;
  3805. }
  3806. /**
  3807. * @brief FIFO pattern.[get]
  3808. *
  3809. * @param ctx Read / write interface definitions
  3810. * @param val get the values of fifo_pattern in reg FIFO_STATUS3 and
  3811. * FIFO_STATUS4, it is recommended to set the BDU bit
  3812. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3813. *
  3814. */
  3815. int32_t lsm6ds3tr_c_fifo_pattern_get(const stmdev_ctx_t *ctx, uint16_t *val)
  3816. {
  3817. lsm6ds3tr_c_fifo_status3_t fifo_status3;
  3818. lsm6ds3tr_c_fifo_status4_t fifo_status4;
  3819. int32_t ret;
  3820. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_STATUS3,
  3821. (uint8_t *)&fifo_status3, 1);
  3822. if (ret == 0)
  3823. {
  3824. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_STATUS4,
  3825. (uint8_t *)&fifo_status4, 1);
  3826. *val = ((uint16_t)fifo_status4.fifo_pattern << 8) +
  3827. fifo_status3.fifo_pattern;
  3828. }
  3829. return ret;
  3830. }
  3831. /**
  3832. * @brief Batching of temperature data[set]
  3833. *
  3834. * @param ctx Read / write interface definitions
  3835. * @param val Change the values of fifo_temp_en in reg FIFO_CTRL2
  3836. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3837. *
  3838. */
  3839. int32_t lsm6ds3tr_c_fifo_temp_batch_set(const stmdev_ctx_t *ctx,
  3840. uint8_t val)
  3841. {
  3842. lsm6ds3tr_c_fifo_ctrl2_t fifo_ctrl2;
  3843. int32_t ret;
  3844. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3845. (uint8_t *)&fifo_ctrl2, 1);
  3846. if (ret == 0)
  3847. {
  3848. fifo_ctrl2.fifo_temp_en = val;
  3849. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3850. (uint8_t *)&fifo_ctrl2, 1);
  3851. }
  3852. return ret;
  3853. }
  3854. /**
  3855. * @brief Batching of temperature data[get]
  3856. *
  3857. * @param ctx Read / write interface definitions
  3858. * @param val Change the values of fifo_temp_en in reg FIFO_CTRL2
  3859. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3860. *
  3861. */
  3862. int32_t lsm6ds3tr_c_fifo_temp_batch_get(const stmdev_ctx_t *ctx,
  3863. uint8_t *val)
  3864. {
  3865. lsm6ds3tr_c_fifo_ctrl2_t fifo_ctrl2;
  3866. int32_t ret;
  3867. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3868. (uint8_t *)&fifo_ctrl2, 1);
  3869. *val = fifo_ctrl2.fifo_temp_en;
  3870. return ret;
  3871. }
  3872. /**
  3873. * @brief Trigger signal for FIFO write operation.[set]
  3874. *
  3875. * @param ctx Read / write interface definitions
  3876. * @param val act on FIFO_CTRL2(timer_pedo_fifo_drdy)
  3877. * and MASTER_CONFIG(data_valid_sel_fifo)
  3878. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3879. *
  3880. */
  3881. int32_t lsm6ds3tr_c_fifo_write_trigger_set(const stmdev_ctx_t *ctx,
  3882. lsm6ds3tr_c_trigger_fifo_t val)
  3883. {
  3884. lsm6ds3tr_c_fifo_ctrl2_t fifo_ctrl2;
  3885. lsm6ds3tr_c_master_config_t master_config;
  3886. int32_t ret;
  3887. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3888. (uint8_t *)&fifo_ctrl2, 1);
  3889. if (ret == 0)
  3890. {
  3891. fifo_ctrl2.timer_pedo_fifo_drdy = (uint8_t)val & 0x01U;
  3892. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3893. (uint8_t *)&fifo_ctrl2, 1);
  3894. if (ret == 0)
  3895. {
  3896. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  3897. (uint8_t *)&master_config, 1);
  3898. if (ret == 0)
  3899. {
  3900. master_config.data_valid_sel_fifo = (((uint8_t)val & 0x02U) >> 1);
  3901. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  3902. (uint8_t *)&master_config, 1);
  3903. }
  3904. }
  3905. }
  3906. return ret;
  3907. }
  3908. /**
  3909. * @brief Trigger signal for FIFO write operation.[get]
  3910. *
  3911. * @param ctx Read / write interface definitions
  3912. * @param val act on FIFO_CTRL2(timer_pedo_fifo_drdy)
  3913. * and MASTER_CONFIG(data_valid_sel_fifo)
  3914. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3915. *
  3916. */
  3917. int32_t lsm6ds3tr_c_fifo_write_trigger_get(const stmdev_ctx_t *ctx,
  3918. lsm6ds3tr_c_trigger_fifo_t *val)
  3919. {
  3920. lsm6ds3tr_c_fifo_ctrl2_t fifo_ctrl2;
  3921. lsm6ds3tr_c_master_config_t master_config;
  3922. int32_t ret;
  3923. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3924. (uint8_t *)&fifo_ctrl2, 1);
  3925. if (ret == 0)
  3926. {
  3927. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  3928. (uint8_t *)&master_config, 1);
  3929. switch ((fifo_ctrl2.timer_pedo_fifo_drdy << 1) +
  3930. fifo_ctrl2. timer_pedo_fifo_drdy)
  3931. {
  3932. case LSM6DS3TR_C_TRG_XL_GY_DRDY:
  3933. *val = LSM6DS3TR_C_TRG_XL_GY_DRDY;
  3934. break;
  3935. case LSM6DS3TR_C_TRG_STEP_DETECT:
  3936. *val = LSM6DS3TR_C_TRG_STEP_DETECT;
  3937. break;
  3938. case LSM6DS3TR_C_TRG_SH_DRDY:
  3939. *val = LSM6DS3TR_C_TRG_SH_DRDY;
  3940. break;
  3941. default:
  3942. *val = LSM6DS3TR_C_TRG_SH_ND;
  3943. break;
  3944. }
  3945. }
  3946. return ret;
  3947. }
  3948. /**
  3949. * @brief Enable pedometer step counter and timestamp as 4th
  3950. * FIFO data set.[set]
  3951. *
  3952. * @param ctx Read / write interface definitions
  3953. * @param val Change the values of timer_pedo_fifo_en in reg FIFO_CTRL2
  3954. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3955. *
  3956. */
  3957. int32_t lsm6ds3tr_c_fifo_pedo_and_timestamp_batch_set(
  3958. stmdev_ctx_t *ctx,
  3959. uint8_t val)
  3960. {
  3961. lsm6ds3tr_c_fifo_ctrl2_t fifo_ctrl2;
  3962. int32_t ret;
  3963. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3964. (uint8_t *)&fifo_ctrl2, 1);
  3965. if (ret == 0)
  3966. {
  3967. fifo_ctrl2.timer_pedo_fifo_en = val;
  3968. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3969. (uint8_t *)&fifo_ctrl2, 1);
  3970. }
  3971. return ret;
  3972. }
  3973. /**
  3974. * @brief Enable pedometer step counter and timestamp as 4th
  3975. * FIFO data set.[get]
  3976. *
  3977. * @param ctx Read / write interface definitions
  3978. * @param val Change the values of timer_pedo_fifo_en in reg FIFO_CTRL2
  3979. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3980. *
  3981. */
  3982. int32_t lsm6ds3tr_c_fifo_pedo_and_timestamp_batch_get(
  3983. stmdev_ctx_t *ctx,
  3984. uint8_t *val)
  3985. {
  3986. lsm6ds3tr_c_fifo_ctrl2_t fifo_ctrl2;
  3987. int32_t ret;
  3988. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3989. (uint8_t *)&fifo_ctrl2, 1);
  3990. *val = fifo_ctrl2.timer_pedo_fifo_en;
  3991. return ret;
  3992. }
  3993. /**
  3994. * @brief Selects Batching Data Rate (writing frequency in FIFO) for
  3995. * accelerometer data.[set]
  3996. *
  3997. * @param ctx Read / write interface definitions
  3998. * @param val Change the values of dec_fifo_xl in reg FIFO_CTRL3
  3999. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4000. *
  4001. */
  4002. int32_t lsm6ds3tr_c_fifo_xl_batch_set(const stmdev_ctx_t *ctx,
  4003. lsm6ds3tr_c_dec_fifo_xl_t val)
  4004. {
  4005. lsm6ds3tr_c_fifo_ctrl3_t fifo_ctrl3;
  4006. int32_t ret;
  4007. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL3,
  4008. (uint8_t *)&fifo_ctrl3, 1);
  4009. if (ret == 0)
  4010. {
  4011. fifo_ctrl3.dec_fifo_xl = (uint8_t)val;
  4012. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL3,
  4013. (uint8_t *)&fifo_ctrl3, 1);
  4014. }
  4015. return ret;
  4016. }
  4017. /**
  4018. * @brief Selects Batching Data Rate (writing frequency in FIFO) for
  4019. * accelerometer data.[get]
  4020. *
  4021. * @param ctx Read / write interface definitions
  4022. * @param val Get the values of dec_fifo_xl in reg FIFO_CTRL3
  4023. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4024. *
  4025. */
  4026. int32_t lsm6ds3tr_c_fifo_xl_batch_get(const stmdev_ctx_t *ctx,
  4027. lsm6ds3tr_c_dec_fifo_xl_t *val)
  4028. {
  4029. lsm6ds3tr_c_fifo_ctrl3_t fifo_ctrl3;
  4030. int32_t ret;
  4031. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL3,
  4032. (uint8_t *)&fifo_ctrl3, 1);
  4033. switch (fifo_ctrl3.dec_fifo_xl)
  4034. {
  4035. case LSM6DS3TR_C_FIFO_XL_DISABLE:
  4036. *val = LSM6DS3TR_C_FIFO_XL_DISABLE;
  4037. break;
  4038. case LSM6DS3TR_C_FIFO_XL_NO_DEC:
  4039. *val = LSM6DS3TR_C_FIFO_XL_NO_DEC;
  4040. break;
  4041. case LSM6DS3TR_C_FIFO_XL_DEC_2:
  4042. *val = LSM6DS3TR_C_FIFO_XL_DEC_2;
  4043. break;
  4044. case LSM6DS3TR_C_FIFO_XL_DEC_3:
  4045. *val = LSM6DS3TR_C_FIFO_XL_DEC_3;
  4046. break;
  4047. case LSM6DS3TR_C_FIFO_XL_DEC_4:
  4048. *val = LSM6DS3TR_C_FIFO_XL_DEC_4;
  4049. break;
  4050. case LSM6DS3TR_C_FIFO_XL_DEC_8:
  4051. *val = LSM6DS3TR_C_FIFO_XL_DEC_8;
  4052. break;
  4053. case LSM6DS3TR_C_FIFO_XL_DEC_16:
  4054. *val = LSM6DS3TR_C_FIFO_XL_DEC_16;
  4055. break;
  4056. case LSM6DS3TR_C_FIFO_XL_DEC_32:
  4057. *val = LSM6DS3TR_C_FIFO_XL_DEC_32;
  4058. break;
  4059. default:
  4060. *val = LSM6DS3TR_C_FIFO_XL_DEC_ND;
  4061. break;
  4062. }
  4063. return ret;
  4064. }
  4065. /**
  4066. * @brief Selects Batching Data Rate (writing frequency in FIFO)
  4067. * for gyroscope data.[set]
  4068. *
  4069. * @param ctx Read / write interface definitions
  4070. * @param val Change the values of dec_fifo_gyro in reg FIFO_CTRL3
  4071. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4072. *
  4073. */
  4074. int32_t lsm6ds3tr_c_fifo_gy_batch_set(const stmdev_ctx_t *ctx,
  4075. lsm6ds3tr_c_dec_fifo_gyro_t val)
  4076. {
  4077. lsm6ds3tr_c_fifo_ctrl3_t fifo_ctrl3;
  4078. int32_t ret;
  4079. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL3,
  4080. (uint8_t *)&fifo_ctrl3, 1);
  4081. if (ret == 0)
  4082. {
  4083. fifo_ctrl3.dec_fifo_gyro = (uint8_t)val;
  4084. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL3,
  4085. (uint8_t *)&fifo_ctrl3, 1);
  4086. }
  4087. return ret;
  4088. }
  4089. /**
  4090. * @brief Selects Batching Data Rate (writing frequency in FIFO)
  4091. * for gyroscope data.[get]
  4092. *
  4093. * @param ctx Read / write interface definitions
  4094. * @param val Get the values of dec_fifo_gyro in reg FIFO_CTRL3
  4095. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4096. *
  4097. */
  4098. int32_t lsm6ds3tr_c_fifo_gy_batch_get(const stmdev_ctx_t *ctx,
  4099. lsm6ds3tr_c_dec_fifo_gyro_t *val)
  4100. {
  4101. lsm6ds3tr_c_fifo_ctrl3_t fifo_ctrl3;
  4102. int32_t ret;
  4103. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL3,
  4104. (uint8_t *)&fifo_ctrl3, 1);
  4105. switch (fifo_ctrl3.dec_fifo_gyro)
  4106. {
  4107. case LSM6DS3TR_C_FIFO_GY_DISABLE:
  4108. *val = LSM6DS3TR_C_FIFO_GY_DISABLE;
  4109. break;
  4110. case LSM6DS3TR_C_FIFO_GY_NO_DEC:
  4111. *val = LSM6DS3TR_C_FIFO_GY_NO_DEC;
  4112. break;
  4113. case LSM6DS3TR_C_FIFO_GY_DEC_2:
  4114. *val = LSM6DS3TR_C_FIFO_GY_DEC_2;
  4115. break;
  4116. case LSM6DS3TR_C_FIFO_GY_DEC_3:
  4117. *val = LSM6DS3TR_C_FIFO_GY_DEC_3;
  4118. break;
  4119. case LSM6DS3TR_C_FIFO_GY_DEC_4:
  4120. *val = LSM6DS3TR_C_FIFO_GY_DEC_4;
  4121. break;
  4122. case LSM6DS3TR_C_FIFO_GY_DEC_8:
  4123. *val = LSM6DS3TR_C_FIFO_GY_DEC_8;
  4124. break;
  4125. case LSM6DS3TR_C_FIFO_GY_DEC_16:
  4126. *val = LSM6DS3TR_C_FIFO_GY_DEC_16;
  4127. break;
  4128. case LSM6DS3TR_C_FIFO_GY_DEC_32:
  4129. *val = LSM6DS3TR_C_FIFO_GY_DEC_32;
  4130. break;
  4131. default:
  4132. *val = LSM6DS3TR_C_FIFO_GY_DEC_ND;
  4133. break;
  4134. }
  4135. return ret;
  4136. }
  4137. /**
  4138. * @brief Selects Batching Data Rate (writing frequency in FIFO)
  4139. * for third data set.[set]
  4140. *
  4141. * @param ctx Read / write interface definitions
  4142. * @param val Change the values of dec_ds3_fifo in reg FIFO_CTRL4
  4143. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4144. *
  4145. */
  4146. int32_t lsm6ds3tr_c_fifo_dataset_3_batch_set(const stmdev_ctx_t *ctx,
  4147. lsm6ds3tr_c_dec_ds3_fifo_t val)
  4148. {
  4149. lsm6ds3tr_c_fifo_ctrl4_t fifo_ctrl4;
  4150. int32_t ret;
  4151. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4152. (uint8_t *)&fifo_ctrl4, 1);
  4153. if (ret == 0)
  4154. {
  4155. fifo_ctrl4.dec_ds3_fifo = (uint8_t)val;
  4156. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4157. (uint8_t *)&fifo_ctrl4, 1);
  4158. }
  4159. return ret;
  4160. }
  4161. /**
  4162. * @brief Selects Batching Data Rate (writing frequency in FIFO)
  4163. * for third data set.[get]
  4164. *
  4165. * @param ctx Read / write interface definitions
  4166. * @param val Get the values of dec_ds3_fifo in reg FIFO_CTRL4
  4167. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4168. *
  4169. */
  4170. int32_t lsm6ds3tr_c_fifo_dataset_3_batch_get(const stmdev_ctx_t *ctx,
  4171. lsm6ds3tr_c_dec_ds3_fifo_t *val)
  4172. {
  4173. lsm6ds3tr_c_fifo_ctrl4_t fifo_ctrl4;
  4174. int32_t ret;
  4175. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4176. (uint8_t *)&fifo_ctrl4, 1);
  4177. switch (fifo_ctrl4.dec_ds3_fifo)
  4178. {
  4179. case LSM6DS3TR_C_FIFO_DS3_DISABLE:
  4180. *val = LSM6DS3TR_C_FIFO_DS3_DISABLE;
  4181. break;
  4182. case LSM6DS3TR_C_FIFO_DS3_NO_DEC:
  4183. *val = LSM6DS3TR_C_FIFO_DS3_NO_DEC;
  4184. break;
  4185. case LSM6DS3TR_C_FIFO_DS3_DEC_2:
  4186. *val = LSM6DS3TR_C_FIFO_DS3_DEC_2;
  4187. break;
  4188. case LSM6DS3TR_C_FIFO_DS3_DEC_3:
  4189. *val = LSM6DS3TR_C_FIFO_DS3_DEC_3;
  4190. break;
  4191. case LSM6DS3TR_C_FIFO_DS3_DEC_4:
  4192. *val = LSM6DS3TR_C_FIFO_DS3_DEC_4;
  4193. break;
  4194. case LSM6DS3TR_C_FIFO_DS3_DEC_8:
  4195. *val = LSM6DS3TR_C_FIFO_DS3_DEC_8;
  4196. break;
  4197. case LSM6DS3TR_C_FIFO_DS3_DEC_16:
  4198. *val = LSM6DS3TR_C_FIFO_DS3_DEC_16;
  4199. break;
  4200. case LSM6DS3TR_C_FIFO_DS3_DEC_32:
  4201. *val = LSM6DS3TR_C_FIFO_DS3_DEC_32;
  4202. break;
  4203. default:
  4204. *val = LSM6DS3TR_C_FIFO_DS3_DEC_ND;
  4205. break;
  4206. }
  4207. return ret;
  4208. }
  4209. /**
  4210. * @brief Selects Batching Data Rate (writing frequency in FIFO)
  4211. * for fourth data set.[set]
  4212. *
  4213. * @param ctx Read / write interface definitions
  4214. * @param val Change the values of dec_ds4_fifo in reg FIFO_CTRL4
  4215. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4216. *
  4217. */
  4218. int32_t lsm6ds3tr_c_fifo_dataset_4_batch_set(const stmdev_ctx_t *ctx,
  4219. lsm6ds3tr_c_dec_ds4_fifo_t val)
  4220. {
  4221. lsm6ds3tr_c_fifo_ctrl4_t fifo_ctrl4;
  4222. int32_t ret;
  4223. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4224. (uint8_t *)&fifo_ctrl4, 1);
  4225. if (ret == 0)
  4226. {
  4227. fifo_ctrl4.dec_ds4_fifo = (uint8_t)val;
  4228. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4229. (uint8_t *)&fifo_ctrl4, 1);
  4230. }
  4231. return ret;
  4232. }
  4233. /**
  4234. * @brief Selects Batching Data Rate (writing frequency in FIFO) for
  4235. * fourth data set.[get]
  4236. *
  4237. * @param ctx Read / write interface definitions
  4238. * @param val Get the values of dec_ds4_fifo in reg FIFO_CTRL4
  4239. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4240. *
  4241. */
  4242. int32_t lsm6ds3tr_c_fifo_dataset_4_batch_get(const stmdev_ctx_t *ctx,
  4243. lsm6ds3tr_c_dec_ds4_fifo_t *val)
  4244. {
  4245. lsm6ds3tr_c_fifo_ctrl4_t fifo_ctrl4;
  4246. int32_t ret;
  4247. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4248. (uint8_t *)&fifo_ctrl4, 1);
  4249. switch (fifo_ctrl4.dec_ds4_fifo)
  4250. {
  4251. case LSM6DS3TR_C_FIFO_DS4_DISABLE:
  4252. *val = LSM6DS3TR_C_FIFO_DS4_DISABLE;
  4253. break;
  4254. case LSM6DS3TR_C_FIFO_DS4_NO_DEC:
  4255. *val = LSM6DS3TR_C_FIFO_DS4_NO_DEC;
  4256. break;
  4257. case LSM6DS3TR_C_FIFO_DS4_DEC_2:
  4258. *val = LSM6DS3TR_C_FIFO_DS4_DEC_2;
  4259. break;
  4260. case LSM6DS3TR_C_FIFO_DS4_DEC_3:
  4261. *val = LSM6DS3TR_C_FIFO_DS4_DEC_3;
  4262. break;
  4263. case LSM6DS3TR_C_FIFO_DS4_DEC_4:
  4264. *val = LSM6DS3TR_C_FIFO_DS4_DEC_4;
  4265. break;
  4266. case LSM6DS3TR_C_FIFO_DS4_DEC_8:
  4267. *val = LSM6DS3TR_C_FIFO_DS4_DEC_8;
  4268. break;
  4269. case LSM6DS3TR_C_FIFO_DS4_DEC_16:
  4270. *val = LSM6DS3TR_C_FIFO_DS4_DEC_16;
  4271. break;
  4272. case LSM6DS3TR_C_FIFO_DS4_DEC_32:
  4273. *val = LSM6DS3TR_C_FIFO_DS4_DEC_32;
  4274. break;
  4275. default:
  4276. *val = LSM6DS3TR_C_FIFO_DS4_DEC_ND;
  4277. break;
  4278. }
  4279. return ret;
  4280. }
  4281. /**
  4282. * @brief 8-bit data storage in FIFO.[set]
  4283. *
  4284. * @param ctx Read / write interface definitions
  4285. * @param val Change the values of only_high_data in reg FIFO_CTRL4
  4286. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4287. *
  4288. */
  4289. int32_t lsm6ds3tr_c_fifo_xl_gy_8bit_format_set(const stmdev_ctx_t *ctx,
  4290. uint8_t val)
  4291. {
  4292. lsm6ds3tr_c_fifo_ctrl4_t fifo_ctrl4;
  4293. int32_t ret;
  4294. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4295. (uint8_t *)&fifo_ctrl4, 1);
  4296. if (ret == 0)
  4297. {
  4298. fifo_ctrl4.only_high_data = val;
  4299. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4300. (uint8_t *)&fifo_ctrl4, 1);
  4301. }
  4302. return ret;
  4303. }
  4304. /**
  4305. * @brief 8-bit data storage in FIFO.[get]
  4306. *
  4307. * @param ctx Read / write interface definitions
  4308. * @param val Change the values of only_high_data in reg FIFO_CTRL4
  4309. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4310. *
  4311. */
  4312. int32_t lsm6ds3tr_c_fifo_xl_gy_8bit_format_get(const stmdev_ctx_t *ctx,
  4313. uint8_t *val)
  4314. {
  4315. lsm6ds3tr_c_fifo_ctrl4_t fifo_ctrl4;
  4316. int32_t ret;
  4317. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4318. (uint8_t *)&fifo_ctrl4, 1);
  4319. *val = fifo_ctrl4.only_high_data;
  4320. return ret;
  4321. }
  4322. /**
  4323. * @brief Sensing chain FIFO stop values memorization at threshold
  4324. * level.[set]
  4325. *
  4326. * @param ctx Read / write interface definitions
  4327. * @param val Change the values of stop_on_fth in reg FIFO_CTRL4
  4328. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4329. *
  4330. */
  4331. int32_t lsm6ds3tr_c_fifo_stop_on_wtm_set(const stmdev_ctx_t *ctx,
  4332. uint8_t val)
  4333. {
  4334. lsm6ds3tr_c_fifo_ctrl4_t fifo_ctrl4;
  4335. int32_t ret;
  4336. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4337. (uint8_t *)&fifo_ctrl4, 1);
  4338. if (ret == 0)
  4339. {
  4340. fifo_ctrl4.stop_on_fth = val;
  4341. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4342. (uint8_t *)&fifo_ctrl4, 1);
  4343. }
  4344. return ret;
  4345. }
  4346. /**
  4347. * @brief Sensing chain FIFO stop values memorization at threshold
  4348. * level.[get]
  4349. *
  4350. * @param ctx Read / write interface definitions
  4351. * @param val Change the values of stop_on_fth in reg FIFO_CTRL4
  4352. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4353. *
  4354. */
  4355. int32_t lsm6ds3tr_c_fifo_stop_on_wtm_get(const stmdev_ctx_t *ctx,
  4356. uint8_t *val)
  4357. {
  4358. lsm6ds3tr_c_fifo_ctrl4_t fifo_ctrl4;
  4359. int32_t ret;
  4360. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4361. (uint8_t *)&fifo_ctrl4, 1);
  4362. *val = fifo_ctrl4.stop_on_fth;
  4363. return ret;
  4364. }
  4365. /**
  4366. * @brief FIFO mode selection.[set]
  4367. *
  4368. * @param ctx Read / write interface definitions
  4369. * @param val Change the values of fifo_mode in reg FIFO_CTRL5
  4370. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4371. *
  4372. */
  4373. int32_t lsm6ds3tr_c_fifo_mode_set(const stmdev_ctx_t *ctx,
  4374. lsm6ds3tr_c_fifo_mode_t val)
  4375. {
  4376. lsm6ds3tr_c_fifo_ctrl5_t fifo_ctrl5;
  4377. int32_t ret;
  4378. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL5,
  4379. (uint8_t *)&fifo_ctrl5, 1);
  4380. if (ret == 0)
  4381. {
  4382. fifo_ctrl5.fifo_mode = (uint8_t)val;
  4383. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL5,
  4384. (uint8_t *)&fifo_ctrl5, 1);
  4385. }
  4386. return ret;
  4387. }
  4388. /**
  4389. * @brief FIFO mode selection.[get]
  4390. *
  4391. * @param ctx Read / write interface definitions
  4392. * @param val Get the values of fifo_mode in reg FIFO_CTRL5
  4393. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4394. *
  4395. */
  4396. int32_t lsm6ds3tr_c_fifo_mode_get(const stmdev_ctx_t *ctx,
  4397. lsm6ds3tr_c_fifo_mode_t *val)
  4398. {
  4399. lsm6ds3tr_c_fifo_ctrl5_t fifo_ctrl5;
  4400. int32_t ret;
  4401. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL5,
  4402. (uint8_t *)&fifo_ctrl5, 1);
  4403. switch (fifo_ctrl5.fifo_mode)
  4404. {
  4405. case LSM6DS3TR_C_BYPASS_MODE:
  4406. *val = LSM6DS3TR_C_BYPASS_MODE;
  4407. break;
  4408. case LSM6DS3TR_C_FIFO_MODE:
  4409. *val = LSM6DS3TR_C_FIFO_MODE;
  4410. break;
  4411. case LSM6DS3TR_C_STREAM_TO_FIFO_MODE:
  4412. *val = LSM6DS3TR_C_STREAM_TO_FIFO_MODE;
  4413. break;
  4414. case LSM6DS3TR_C_BYPASS_TO_STREAM_MODE:
  4415. *val = LSM6DS3TR_C_BYPASS_TO_STREAM_MODE;
  4416. break;
  4417. case LSM6DS3TR_C_STREAM_MODE:
  4418. *val = LSM6DS3TR_C_STREAM_MODE;
  4419. break;
  4420. default:
  4421. *val = LSM6DS3TR_C_FIFO_MODE_ND;
  4422. break;
  4423. }
  4424. return ret;
  4425. }
  4426. /**
  4427. * @brief FIFO ODR selection, setting FIFO_MODE also.[set]
  4428. *
  4429. * @param ctx Read / write interface definitions
  4430. * @param val Change the values of odr_fifo in reg FIFO_CTRL5
  4431. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4432. *
  4433. */
  4434. int32_t lsm6ds3tr_c_fifo_data_rate_set(const stmdev_ctx_t *ctx,
  4435. lsm6ds3tr_c_odr_fifo_t val)
  4436. {
  4437. lsm6ds3tr_c_fifo_ctrl5_t fifo_ctrl5;
  4438. int32_t ret;
  4439. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL5,
  4440. (uint8_t *)&fifo_ctrl5, 1);
  4441. if (ret == 0)
  4442. {
  4443. fifo_ctrl5.odr_fifo = (uint8_t)val;
  4444. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL5,
  4445. (uint8_t *)&fifo_ctrl5, 1);
  4446. }
  4447. return ret;
  4448. }
  4449. /**
  4450. * @brief FIFO ODR selection, setting FIFO_MODE also.[get]
  4451. *
  4452. * @param ctx Read / write interface definitions
  4453. * @param val Get the values of odr_fifo in reg FIFO_CTRL5
  4454. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4455. *
  4456. */
  4457. int32_t lsm6ds3tr_c_fifo_data_rate_get(const stmdev_ctx_t *ctx,
  4458. lsm6ds3tr_c_odr_fifo_t *val)
  4459. {
  4460. lsm6ds3tr_c_fifo_ctrl5_t fifo_ctrl5;
  4461. int32_t ret;
  4462. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL5,
  4463. (uint8_t *)&fifo_ctrl5, 1);
  4464. switch (fifo_ctrl5.odr_fifo)
  4465. {
  4466. case LSM6DS3TR_C_FIFO_DISABLE:
  4467. *val = LSM6DS3TR_C_FIFO_DISABLE;
  4468. break;
  4469. case LSM6DS3TR_C_FIFO_12Hz5:
  4470. *val = LSM6DS3TR_C_FIFO_12Hz5;
  4471. break;
  4472. case LSM6DS3TR_C_FIFO_26Hz:
  4473. *val = LSM6DS3TR_C_FIFO_26Hz;
  4474. break;
  4475. case LSM6DS3TR_C_FIFO_52Hz:
  4476. *val = LSM6DS3TR_C_FIFO_52Hz;
  4477. break;
  4478. case LSM6DS3TR_C_FIFO_104Hz:
  4479. *val = LSM6DS3TR_C_FIFO_104Hz;
  4480. break;
  4481. case LSM6DS3TR_C_FIFO_208Hz:
  4482. *val = LSM6DS3TR_C_FIFO_208Hz;
  4483. break;
  4484. case LSM6DS3TR_C_FIFO_416Hz:
  4485. *val = LSM6DS3TR_C_FIFO_416Hz;
  4486. break;
  4487. case LSM6DS3TR_C_FIFO_833Hz:
  4488. *val = LSM6DS3TR_C_FIFO_833Hz;
  4489. break;
  4490. case LSM6DS3TR_C_FIFO_1k66Hz:
  4491. *val = LSM6DS3TR_C_FIFO_1k66Hz;
  4492. break;
  4493. case LSM6DS3TR_C_FIFO_3k33Hz:
  4494. *val = LSM6DS3TR_C_FIFO_3k33Hz;
  4495. break;
  4496. case LSM6DS3TR_C_FIFO_6k66Hz:
  4497. *val = LSM6DS3TR_C_FIFO_6k66Hz;
  4498. break;
  4499. default:
  4500. *val = LSM6DS3TR_C_FIFO_RATE_ND;
  4501. break;
  4502. }
  4503. return ret;
  4504. }
  4505. /**
  4506. * @}
  4507. *
  4508. */
  4509. /**
  4510. * @defgroup LSM6DS3TR_C_DEN_functionality
  4511. * @brief This section groups all the functions concerning DEN
  4512. * functionality.
  4513. * @{
  4514. *
  4515. */
  4516. /**
  4517. * @brief DEN active level configuration.[set]
  4518. *
  4519. * @param ctx Read / write interface definitions
  4520. * @param val Change the values of den_lh in reg CTRL5_C
  4521. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4522. *
  4523. */
  4524. int32_t lsm6ds3tr_c_den_polarity_set(const stmdev_ctx_t *ctx,
  4525. lsm6ds3tr_c_den_lh_t val)
  4526. {
  4527. lsm6ds3tr_c_ctrl5_c_t ctrl5_c;
  4528. int32_t ret;
  4529. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  4530. (uint8_t *)&ctrl5_c, 1);
  4531. if (ret == 0)
  4532. {
  4533. ctrl5_c.den_lh = (uint8_t)val;
  4534. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  4535. (uint8_t *)&ctrl5_c, 1);
  4536. }
  4537. return ret;
  4538. }
  4539. /**
  4540. * @brief DEN active level configuration.[get]
  4541. *
  4542. * @param ctx Read / write interface definitions
  4543. * @param val Get the values of den_lh in reg CTRL5_C
  4544. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4545. *
  4546. */
  4547. int32_t lsm6ds3tr_c_den_polarity_get(const stmdev_ctx_t *ctx,
  4548. lsm6ds3tr_c_den_lh_t *val)
  4549. {
  4550. lsm6ds3tr_c_ctrl5_c_t ctrl5_c;
  4551. int32_t ret;
  4552. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  4553. (uint8_t *)&ctrl5_c, 1);
  4554. switch (ctrl5_c.den_lh)
  4555. {
  4556. case LSM6DS3TR_C_DEN_ACT_LOW:
  4557. *val = LSM6DS3TR_C_DEN_ACT_LOW;
  4558. break;
  4559. case LSM6DS3TR_C_DEN_ACT_HIGH:
  4560. *val = LSM6DS3TR_C_DEN_ACT_HIGH;
  4561. break;
  4562. default:
  4563. *val = LSM6DS3TR_C_DEN_POL_ND;
  4564. break;
  4565. }
  4566. return ret;
  4567. }
  4568. /**
  4569. * @brief DEN functionality marking mode[set]
  4570. *
  4571. * @param ctx Read / write interface definitions
  4572. * @param val Change the values of den_mode in reg CTRL6_C
  4573. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4574. *
  4575. */
  4576. int32_t lsm6ds3tr_c_den_mode_set(const stmdev_ctx_t *ctx,
  4577. lsm6ds3tr_c_den_mode_t val)
  4578. {
  4579. lsm6ds3tr_c_ctrl6_c_t ctrl6_c;
  4580. int32_t ret;
  4581. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  4582. (uint8_t *)&ctrl6_c, 1);
  4583. if (ret == 0)
  4584. {
  4585. ctrl6_c.den_mode = (uint8_t)val;
  4586. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  4587. (uint8_t *)&ctrl6_c, 1);
  4588. }
  4589. return ret;
  4590. }
  4591. /**
  4592. * @brief DEN functionality marking mode[get]
  4593. *
  4594. * @param ctx Read / write interface definitions
  4595. * @param val Change the values of den_mode in reg CTRL6_C
  4596. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4597. *
  4598. */
  4599. int32_t lsm6ds3tr_c_den_mode_get(const stmdev_ctx_t *ctx,
  4600. lsm6ds3tr_c_den_mode_t *val)
  4601. {
  4602. lsm6ds3tr_c_ctrl6_c_t ctrl6_c;
  4603. int32_t ret;
  4604. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  4605. (uint8_t *)&ctrl6_c, 1);
  4606. switch (ctrl6_c.den_mode)
  4607. {
  4608. case LSM6DS3TR_C_DEN_DISABLE:
  4609. *val = LSM6DS3TR_C_DEN_DISABLE;
  4610. break;
  4611. case LSM6DS3TR_C_LEVEL_LETCHED:
  4612. *val = LSM6DS3TR_C_LEVEL_LETCHED;
  4613. break;
  4614. case LSM6DS3TR_C_LEVEL_TRIGGER:
  4615. *val = LSM6DS3TR_C_LEVEL_TRIGGER;
  4616. break;
  4617. case LSM6DS3TR_C_EDGE_TRIGGER:
  4618. *val = LSM6DS3TR_C_EDGE_TRIGGER;
  4619. break;
  4620. default:
  4621. *val = LSM6DS3TR_C_DEN_MODE_ND;
  4622. break;
  4623. }
  4624. return ret;
  4625. }
  4626. /**
  4627. * @brief Extend DEN functionality to accelerometer sensor.[set]
  4628. *
  4629. * @param ctx Read / write interface definitions
  4630. * @param val Change the values of den_xl_g in reg CTRL9_XL
  4631. * and den_xl_en in CTRL4_C.
  4632. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4633. *
  4634. */
  4635. int32_t lsm6ds3tr_c_den_enable_set(const stmdev_ctx_t *ctx,
  4636. lsm6ds3tr_c_den_xl_en_t val)
  4637. {
  4638. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  4639. lsm6ds3tr_c_ctrl9_xl_t ctrl9_xl;
  4640. int32_t ret;
  4641. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4642. (uint8_t *)&ctrl9_xl, 1);
  4643. if (ret == 0)
  4644. {
  4645. ctrl9_xl.den_xl_g = (uint8_t)val & 0x01U;
  4646. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4647. (uint8_t *)&ctrl9_xl, 1);
  4648. if (ret == 0)
  4649. {
  4650. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  4651. (uint8_t *)&ctrl4_c, 1);
  4652. if (ret == 0)
  4653. {
  4654. ctrl4_c.den_xl_en = (uint8_t)val & 0x02U;
  4655. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  4656. (uint8_t *)&ctrl4_c, 1);
  4657. }
  4658. }
  4659. }
  4660. return ret;
  4661. }
  4662. /**
  4663. * @brief Extend DEN functionality to accelerometer sensor. [get]
  4664. *
  4665. * @param ctx Read / write interface definitions
  4666. * @param val Get the values of den_xl_g in reg CTRL9_XL
  4667. * and den_xl_en in CTRL4_C.
  4668. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4669. *
  4670. */
  4671. int32_t lsm6ds3tr_c_den_enable_get(const stmdev_ctx_t *ctx,
  4672. lsm6ds3tr_c_den_xl_en_t *val)
  4673. {
  4674. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  4675. lsm6ds3tr_c_ctrl9_xl_t ctrl9_xl;
  4676. int32_t ret;
  4677. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  4678. (uint8_t *)&ctrl4_c, 1);
  4679. if (ret == 0)
  4680. {
  4681. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4682. (uint8_t *)&ctrl9_xl, 1);
  4683. switch ((ctrl4_c.den_xl_en << 1) + ctrl9_xl.den_xl_g)
  4684. {
  4685. case LSM6DS3TR_C_STAMP_IN_GY_DATA:
  4686. *val = LSM6DS3TR_C_STAMP_IN_GY_DATA;
  4687. break;
  4688. case LSM6DS3TR_C_STAMP_IN_XL_DATA:
  4689. *val = LSM6DS3TR_C_STAMP_IN_XL_DATA;
  4690. break;
  4691. case LSM6DS3TR_C_STAMP_IN_GY_XL_DATA:
  4692. *val = LSM6DS3TR_C_STAMP_IN_GY_XL_DATA;
  4693. break;
  4694. default:
  4695. *val = LSM6DS3TR_C_DEN_STAMP_ND;
  4696. break;
  4697. }
  4698. }
  4699. return ret;
  4700. }
  4701. /**
  4702. * @brief DEN value stored in LSB of Z-axis.[set]
  4703. *
  4704. * @param ctx Read / write interface definitions
  4705. * @param val Change the values of den_z in reg CTRL9_XL
  4706. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4707. *
  4708. */
  4709. int32_t lsm6ds3tr_c_den_mark_axis_z_set(const stmdev_ctx_t *ctx,
  4710. uint8_t val)
  4711. {
  4712. lsm6ds3tr_c_ctrl9_xl_t ctrl9_xl;
  4713. int32_t ret;
  4714. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4715. (uint8_t *)&ctrl9_xl, 1);
  4716. if (ret == 0)
  4717. {
  4718. ctrl9_xl.den_z = val;
  4719. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4720. (uint8_t *)&ctrl9_xl, 1);
  4721. }
  4722. return ret;
  4723. }
  4724. /**
  4725. * @brief DEN value stored in LSB of Z-axis.[get]
  4726. *
  4727. * @param ctx Read / write interface definitions
  4728. * @param val Change the values of den_z in reg CTRL9_XL
  4729. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4730. *
  4731. */
  4732. int32_t lsm6ds3tr_c_den_mark_axis_z_get(const stmdev_ctx_t *ctx,
  4733. uint8_t *val)
  4734. {
  4735. lsm6ds3tr_c_ctrl9_xl_t ctrl9_xl;
  4736. int32_t ret;
  4737. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4738. (uint8_t *)&ctrl9_xl, 1);
  4739. *val = ctrl9_xl.den_z;
  4740. return ret;
  4741. }
  4742. /**
  4743. * @brief DEN value stored in LSB of Y-axis.[set]
  4744. *
  4745. * @param ctx Read / write interface definitions
  4746. * @param val Change the values of den_y in reg CTRL9_XL
  4747. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4748. *
  4749. */
  4750. int32_t lsm6ds3tr_c_den_mark_axis_y_set(const stmdev_ctx_t *ctx,
  4751. uint8_t val)
  4752. {
  4753. lsm6ds3tr_c_ctrl9_xl_t ctrl9_xl;
  4754. int32_t ret;
  4755. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4756. (uint8_t *)&ctrl9_xl, 1);
  4757. if (ret == 0)
  4758. {
  4759. ctrl9_xl.den_y = val;
  4760. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4761. (uint8_t *)&ctrl9_xl, 1);
  4762. }
  4763. return ret;
  4764. }
  4765. /**
  4766. * @brief DEN value stored in LSB of Y-axis.[get]
  4767. *
  4768. * @param ctx Read / write interface definitions
  4769. * @param val Change the values of den_y in reg CTRL9_XL
  4770. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4771. *
  4772. */
  4773. int32_t lsm6ds3tr_c_den_mark_axis_y_get(const stmdev_ctx_t *ctx,
  4774. uint8_t *val)
  4775. {
  4776. lsm6ds3tr_c_ctrl9_xl_t ctrl9_xl;
  4777. int32_t ret;
  4778. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4779. (uint8_t *)&ctrl9_xl, 1);
  4780. *val = ctrl9_xl.den_y;
  4781. return ret;
  4782. }
  4783. /**
  4784. * @brief DEN value stored in LSB of X-axis.[set]
  4785. *
  4786. * @param ctx Read / write interface definitions
  4787. * @param val Change the values of den_x in reg CTRL9_XL
  4788. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4789. *
  4790. */
  4791. int32_t lsm6ds3tr_c_den_mark_axis_x_set(const stmdev_ctx_t *ctx,
  4792. uint8_t val)
  4793. {
  4794. lsm6ds3tr_c_ctrl9_xl_t ctrl9_xl;
  4795. int32_t ret;
  4796. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4797. (uint8_t *)&ctrl9_xl, 1);
  4798. if (ret == 0)
  4799. {
  4800. ctrl9_xl.den_x = val;
  4801. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4802. (uint8_t *)&ctrl9_xl, 1);
  4803. }
  4804. return ret;
  4805. }
  4806. /**
  4807. * @brief DEN value stored in LSB of X-axis.[get]
  4808. *
  4809. * @param ctx Read / write interface definitions
  4810. * @param val Change the values of den_x in reg CTRL9_XL
  4811. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4812. *
  4813. */
  4814. int32_t lsm6ds3tr_c_den_mark_axis_x_get(const stmdev_ctx_t *ctx,
  4815. uint8_t *val)
  4816. {
  4817. lsm6ds3tr_c_ctrl9_xl_t ctrl9_xl;
  4818. int32_t ret;
  4819. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4820. (uint8_t *)&ctrl9_xl, 1);
  4821. *val = ctrl9_xl.den_x;
  4822. return ret;
  4823. }
  4824. /**
  4825. * @}
  4826. *
  4827. */
  4828. /**
  4829. * @defgroup LSM6DS3TR_C_Pedometer
  4830. * @brief This section groups all the functions that manage pedometer.
  4831. * @{
  4832. *
  4833. */
  4834. /**
  4835. * @brief Reset pedometer step counter.[set]
  4836. *
  4837. * @param ctx Read / write interface definitions
  4838. * @param val Change the values of pedo_rst_step in reg CTRL10_C
  4839. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4840. *
  4841. */
  4842. int32_t lsm6ds3tr_c_pedo_step_reset_set(const stmdev_ctx_t *ctx,
  4843. uint8_t val)
  4844. {
  4845. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  4846. int32_t ret;
  4847. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  4848. (uint8_t *)&ctrl10_c, 1);
  4849. if (ret == 0)
  4850. {
  4851. ctrl10_c.pedo_rst_step = val;
  4852. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  4853. (uint8_t *)&ctrl10_c, 1);
  4854. }
  4855. return ret;
  4856. }
  4857. /**
  4858. * @brief Reset pedometer step counter.[get]
  4859. *
  4860. * @param ctx Read / write interface definitions
  4861. * @param val Change the values of pedo_rst_step in reg CTRL10_C
  4862. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4863. *
  4864. */
  4865. int32_t lsm6ds3tr_c_pedo_step_reset_get(const stmdev_ctx_t *ctx,
  4866. uint8_t *val)
  4867. {
  4868. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  4869. int32_t ret;
  4870. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  4871. (uint8_t *)&ctrl10_c, 1);
  4872. *val = ctrl10_c.pedo_rst_step;
  4873. return ret;
  4874. }
  4875. /**
  4876. * @brief Enable pedometer algorithm.[set]
  4877. *
  4878. * @param ctx Read / write interface definitions
  4879. * @param val Change the values of pedo_en in reg CTRL10_C
  4880. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4881. *
  4882. */
  4883. int32_t lsm6ds3tr_c_pedo_sens_set(const stmdev_ctx_t *ctx, uint8_t val)
  4884. {
  4885. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  4886. int32_t ret;
  4887. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  4888. (uint8_t *)&ctrl10_c, 1);
  4889. if (ret == 0)
  4890. {
  4891. ctrl10_c.pedo_en = val;
  4892. if (val != 0x00U)
  4893. {
  4894. ctrl10_c.func_en = val;
  4895. }
  4896. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  4897. (uint8_t *)&ctrl10_c, 1);
  4898. }
  4899. return ret;
  4900. }
  4901. /**
  4902. * @brief pedo_sens: Enable pedometer algorithm.[get]
  4903. *
  4904. * @param ctx Read / write interface definitions
  4905. * @param val Change the values of pedo_en in reg CTRL10_C
  4906. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4907. *
  4908. */
  4909. int32_t lsm6ds3tr_c_pedo_sens_get(const stmdev_ctx_t *ctx, uint8_t *val)
  4910. {
  4911. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  4912. int32_t ret;
  4913. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  4914. (uint8_t *)&ctrl10_c, 1);
  4915. *val = ctrl10_c.pedo_en;
  4916. return ret;
  4917. }
  4918. /**
  4919. * @brief Minimum threshold to detect a peak. Default is 10h.[set]
  4920. *
  4921. * @param ctx Read / write interface definitions
  4922. * @param val Change the values of ths_min in reg
  4923. * CONFIG_PEDO_THS_MIN
  4924. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4925. *
  4926. */
  4927. int32_t lsm6ds3tr_c_pedo_threshold_set(const stmdev_ctx_t *ctx, uint8_t val)
  4928. {
  4929. lsm6ds3tr_c_config_pedo_ths_min_t config_pedo_ths_min;
  4930. int32_t ret;
  4931. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  4932. if (ret == 0)
  4933. {
  4934. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CONFIG_PEDO_THS_MIN,
  4935. (uint8_t *)&config_pedo_ths_min, 1);
  4936. if (ret == 0)
  4937. {
  4938. config_pedo_ths_min.ths_min = val;
  4939. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CONFIG_PEDO_THS_MIN,
  4940. (uint8_t *)&config_pedo_ths_min, 1);
  4941. if (ret == 0)
  4942. {
  4943. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  4944. }
  4945. }
  4946. }
  4947. return ret;
  4948. }
  4949. /**
  4950. * @brief Minimum threshold to detect a peak. Default is 10h.[get]
  4951. *
  4952. * @param ctx Read / write interface definitions
  4953. * @param val Change the values of ths_min in reg CONFIG_PEDO_THS_MIN
  4954. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4955. *
  4956. */
  4957. int32_t lsm6ds3tr_c_pedo_threshold_get(const stmdev_ctx_t *ctx,
  4958. uint8_t *val)
  4959. {
  4960. lsm6ds3tr_c_config_pedo_ths_min_t config_pedo_ths_min;
  4961. int32_t ret;
  4962. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  4963. if (ret == 0)
  4964. {
  4965. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CONFIG_PEDO_THS_MIN,
  4966. (uint8_t *)&config_pedo_ths_min, 1);
  4967. if (ret == 0)
  4968. {
  4969. *val = config_pedo_ths_min.ths_min;
  4970. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  4971. }
  4972. }
  4973. return ret;
  4974. }
  4975. /**
  4976. * @brief pedo_full_scale: Pedometer data range.[set]
  4977. *
  4978. * @param ctx Read / write interface definitions
  4979. * @param val Change the values of pedo_fs in
  4980. * reg CONFIG_PEDO_THS_MIN
  4981. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4982. *
  4983. */
  4984. int32_t lsm6ds3tr_c_pedo_full_scale_set(const stmdev_ctx_t *ctx,
  4985. lsm6ds3tr_c_pedo_fs_t val)
  4986. {
  4987. lsm6ds3tr_c_config_pedo_ths_min_t config_pedo_ths_min;
  4988. int32_t ret;
  4989. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  4990. if (ret == 0)
  4991. {
  4992. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CONFIG_PEDO_THS_MIN,
  4993. (uint8_t *)&config_pedo_ths_min, 1);
  4994. if (ret == 0)
  4995. {
  4996. config_pedo_ths_min.pedo_fs = (uint8_t) val;
  4997. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CONFIG_PEDO_THS_MIN,
  4998. (uint8_t *)&config_pedo_ths_min, 1);
  4999. if (ret == 0)
  5000. {
  5001. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5002. }
  5003. }
  5004. }
  5005. return ret;
  5006. }
  5007. /**
  5008. * @brief Pedometer data range.[get]
  5009. *
  5010. * @param ctx Read / write interface definitions
  5011. * @param val Get the values of pedo_fs in
  5012. * reg CONFIG_PEDO_THS_MIN
  5013. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5014. *
  5015. */
  5016. int32_t lsm6ds3tr_c_pedo_full_scale_get(const stmdev_ctx_t *ctx,
  5017. lsm6ds3tr_c_pedo_fs_t *val)
  5018. {
  5019. lsm6ds3tr_c_config_pedo_ths_min_t config_pedo_ths_min;
  5020. int32_t ret;
  5021. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5022. if (ret == 0)
  5023. {
  5024. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CONFIG_PEDO_THS_MIN,
  5025. (uint8_t *)&config_pedo_ths_min, 1);
  5026. if (ret == 0)
  5027. {
  5028. switch (config_pedo_ths_min.pedo_fs)
  5029. {
  5030. case LSM6DS3TR_C_PEDO_AT_2g:
  5031. *val = LSM6DS3TR_C_PEDO_AT_2g;
  5032. break;
  5033. case LSM6DS3TR_C_PEDO_AT_4g:
  5034. *val = LSM6DS3TR_C_PEDO_AT_4g;
  5035. break;
  5036. default:
  5037. *val = LSM6DS3TR_C_PEDO_FS_ND;
  5038. break;
  5039. }
  5040. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5041. }
  5042. }
  5043. return ret;
  5044. }
  5045. /**
  5046. * @brief Pedometer debounce configuration register (r/w).[set]
  5047. *
  5048. * @param ctx Read / write interface definitions
  5049. * @param val Change the values of deb_step in reg PEDO_DEB_REG
  5050. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5051. *
  5052. */
  5053. int32_t lsm6ds3tr_c_pedo_debounce_steps_set(const stmdev_ctx_t *ctx,
  5054. uint8_t val)
  5055. {
  5056. lsm6ds3tr_c_pedo_deb_reg_t pedo_deb_reg;
  5057. int32_t ret;
  5058. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5059. if (ret == 0)
  5060. {
  5061. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_PEDO_DEB_REG,
  5062. (uint8_t *)&pedo_deb_reg, 1);
  5063. if (ret == 0)
  5064. {
  5065. pedo_deb_reg.deb_step = val;
  5066. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_PEDO_DEB_REG,
  5067. (uint8_t *)&pedo_deb_reg, 1);
  5068. if (ret == 0)
  5069. {
  5070. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5071. }
  5072. }
  5073. }
  5074. return ret;
  5075. }
  5076. /**
  5077. * @brief Pedometer debounce configuration register (r/w).[get]
  5078. *
  5079. * @param ctx Read / write interface definitions
  5080. * @param val Change the values of deb_step in reg PEDO_DEB_REG
  5081. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5082. *
  5083. */
  5084. int32_t lsm6ds3tr_c_pedo_debounce_steps_get(const stmdev_ctx_t *ctx,
  5085. uint8_t *val)
  5086. {
  5087. lsm6ds3tr_c_pedo_deb_reg_t pedo_deb_reg;
  5088. int32_t ret;
  5089. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5090. if (ret == 0)
  5091. {
  5092. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_PEDO_DEB_REG,
  5093. (uint8_t *)&pedo_deb_reg, 1);
  5094. if (ret == 0)
  5095. {
  5096. *val = pedo_deb_reg.deb_step;
  5097. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5098. }
  5099. }
  5100. return ret;
  5101. }
  5102. /**
  5103. * @brief Debounce time. If the time between two consecutive steps is
  5104. * greater than DEB_TIME*80ms, the debouncer is reactivated.
  5105. * Default value: 01101[set]
  5106. *
  5107. * @param ctx Read / write interface definitions
  5108. * @param val Change the values of deb_time in reg PEDO_DEB_REG
  5109. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5110. *
  5111. */
  5112. int32_t lsm6ds3tr_c_pedo_timeout_set(const stmdev_ctx_t *ctx, uint8_t val)
  5113. {
  5114. lsm6ds3tr_c_pedo_deb_reg_t pedo_deb_reg;
  5115. int32_t ret;
  5116. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5117. if (ret == 0)
  5118. {
  5119. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_PEDO_DEB_REG,
  5120. (uint8_t *)&pedo_deb_reg, 1);
  5121. if (ret == 0)
  5122. {
  5123. pedo_deb_reg.deb_time = val;
  5124. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_PEDO_DEB_REG,
  5125. (uint8_t *)&pedo_deb_reg, 1);
  5126. if (ret == 0)
  5127. {
  5128. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5129. }
  5130. }
  5131. }
  5132. return ret;
  5133. }
  5134. /**
  5135. * @brief Debounce time. If the time between two consecutive steps is
  5136. * greater than DEB_TIME*80ms, the debouncer is reactivated.
  5137. * Default value: 01101[get]
  5138. *
  5139. * @param ctx Read / write interface definitions
  5140. * @param val Change the values of deb_time in reg PEDO_DEB_REG
  5141. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5142. *
  5143. */
  5144. int32_t lsm6ds3tr_c_pedo_timeout_get(const stmdev_ctx_t *ctx, uint8_t *val)
  5145. {
  5146. lsm6ds3tr_c_pedo_deb_reg_t pedo_deb_reg;
  5147. int32_t ret;
  5148. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5149. if (ret == 0)
  5150. {
  5151. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_PEDO_DEB_REG,
  5152. (uint8_t *)&pedo_deb_reg, 1);
  5153. if (ret == 0)
  5154. {
  5155. *val = pedo_deb_reg.deb_time;
  5156. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5157. }
  5158. }
  5159. return ret;
  5160. }
  5161. /**
  5162. * @brief Time period register for step detection on delta time (r/w).[set]
  5163. *
  5164. * @param ctx Read / write interface definitions
  5165. * @param buff Buffer that contains data to write
  5166. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5167. *
  5168. */
  5169. int32_t lsm6ds3tr_c_pedo_steps_period_set(const stmdev_ctx_t *ctx,
  5170. uint8_t *buff)
  5171. {
  5172. int32_t ret;
  5173. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5174. if (ret == 0)
  5175. {
  5176. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_STEP_COUNT_DELTA, buff, 1);
  5177. if (ret == 0)
  5178. {
  5179. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5180. }
  5181. }
  5182. return ret;
  5183. }
  5184. /**
  5185. * @brief Time period register for step detection on delta time (r/w).[get]
  5186. *
  5187. * @param ctx Read / write interface definitions
  5188. * @param buff Buffer that stores data read
  5189. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5190. *
  5191. */
  5192. int32_t lsm6ds3tr_c_pedo_steps_period_get(const stmdev_ctx_t *ctx,
  5193. uint8_t *buff)
  5194. {
  5195. int32_t ret;
  5196. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5197. if (ret == 0)
  5198. {
  5199. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_STEP_COUNT_DELTA, buff, 1);
  5200. if (ret == 0)
  5201. {
  5202. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5203. }
  5204. }
  5205. return ret;
  5206. }
  5207. /**
  5208. * @}
  5209. *
  5210. */
  5211. /**
  5212. * @defgroup LSM6DS3TR_C_significant_motion
  5213. * @brief This section groups all the functions that manage the
  5214. * significant motion detection.
  5215. * @{
  5216. *
  5217. */
  5218. /**
  5219. * @brief Enable significant motion detection function.[set]
  5220. *
  5221. * @param ctx Read / write interface definitions
  5222. * @param val Change the values of sign_motion_en in reg CTRL10_C
  5223. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5224. *
  5225. */
  5226. int32_t lsm6ds3tr_c_motion_sens_set(const stmdev_ctx_t *ctx, uint8_t val)
  5227. {
  5228. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  5229. int32_t ret;
  5230. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5231. (uint8_t *)&ctrl10_c, 1);
  5232. if (ret == 0)
  5233. {
  5234. ctrl10_c.sign_motion_en = val;
  5235. if (val != 0x00U)
  5236. {
  5237. ctrl10_c.func_en = val;
  5238. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5239. (uint8_t *)&ctrl10_c, 1);
  5240. }
  5241. }
  5242. return ret;
  5243. }
  5244. /**
  5245. * @brief Enable significant motion detection function.[get]
  5246. *
  5247. * @param ctx Read / write interface definitions
  5248. * @param val Change the values of sign_motion_en in reg CTRL10_C
  5249. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5250. *
  5251. */
  5252. int32_t lsm6ds3tr_c_motion_sens_get(const stmdev_ctx_t *ctx, uint8_t *val)
  5253. {
  5254. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  5255. int32_t ret;
  5256. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5257. (uint8_t *)&ctrl10_c, 1);
  5258. *val = ctrl10_c.sign_motion_en;
  5259. return ret;
  5260. }
  5261. /**
  5262. * @brief Significant motion threshold.[set]
  5263. *
  5264. * @param ctx Read / write interface definitions
  5265. * @param buff Buffer that store significant motion threshold.
  5266. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5267. *
  5268. */
  5269. int32_t lsm6ds3tr_c_motion_threshold_set(const stmdev_ctx_t *ctx,
  5270. uint8_t *buff)
  5271. {
  5272. int32_t ret;
  5273. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5274. if (ret == 0)
  5275. {
  5276. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SM_THS, buff, 1);
  5277. if (ret == 0)
  5278. {
  5279. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5280. }
  5281. }
  5282. return ret;
  5283. }
  5284. /**
  5285. * @brief Significant motion threshold.[get]
  5286. *
  5287. * @param ctx Read / write interface definitions
  5288. * @param buff Buffer that store significant motion threshold.
  5289. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5290. *
  5291. */
  5292. int32_t lsm6ds3tr_c_motion_threshold_get(const stmdev_ctx_t *ctx,
  5293. uint8_t *buff)
  5294. {
  5295. int32_t ret;
  5296. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5297. if (ret == 0)
  5298. {
  5299. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SM_THS, buff, 1);
  5300. if (ret == 0)
  5301. {
  5302. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5303. }
  5304. }
  5305. return ret;
  5306. }
  5307. /**
  5308. * @}
  5309. *
  5310. */
  5311. /**
  5312. * @defgroup LSM6DS3TR_C_tilt_detection
  5313. * @brief This section groups all the functions that manage the tilt
  5314. * event detection.
  5315. * @{
  5316. *
  5317. */
  5318. /**
  5319. * @brief Enable tilt calculation.[set]
  5320. *
  5321. * @param ctx Read / write interface definitions
  5322. * @param val Change the values of tilt_en in reg CTRL10_C
  5323. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5324. *
  5325. */
  5326. int32_t lsm6ds3tr_c_tilt_sens_set(const stmdev_ctx_t *ctx, uint8_t val)
  5327. {
  5328. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  5329. int32_t ret;
  5330. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5331. (uint8_t *)&ctrl10_c, 1);
  5332. if (ret == 0)
  5333. {
  5334. ctrl10_c.tilt_en = val;
  5335. if (val != 0x00U)
  5336. {
  5337. ctrl10_c.func_en = val;
  5338. }
  5339. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5340. (uint8_t *)&ctrl10_c, 1);
  5341. }
  5342. return ret;
  5343. }
  5344. /**
  5345. * @brief Enable tilt calculation.[get]
  5346. *
  5347. * @param ctx Read / write interface definitions
  5348. * @param val Change the values of tilt_en in reg CTRL10_C
  5349. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5350. *
  5351. */
  5352. int32_t lsm6ds3tr_c_tilt_sens_get(const stmdev_ctx_t *ctx, uint8_t *val)
  5353. {
  5354. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  5355. int32_t ret;
  5356. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5357. (uint8_t *)&ctrl10_c, 1);
  5358. *val = ctrl10_c.tilt_en;
  5359. return ret;
  5360. }
  5361. /**
  5362. * @brief Enable tilt calculation.[set]
  5363. *
  5364. * @param ctx Read / write interface definitions
  5365. * @param val Change the values of tilt_en in reg CTRL10_C
  5366. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5367. *
  5368. */
  5369. int32_t lsm6ds3tr_c_wrist_tilt_sens_set(const stmdev_ctx_t *ctx,
  5370. uint8_t val)
  5371. {
  5372. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  5373. int32_t ret;
  5374. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5375. (uint8_t *)&ctrl10_c, 1);
  5376. if (ret == 0)
  5377. {
  5378. ctrl10_c.wrist_tilt_en = val;
  5379. if (val != 0x00U)
  5380. {
  5381. ctrl10_c.func_en = val;
  5382. }
  5383. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5384. (uint8_t *)&ctrl10_c, 1);
  5385. }
  5386. return ret;
  5387. }
  5388. /**
  5389. * @brief Enable tilt calculation.[get]
  5390. *
  5391. * @param ctx Read / write interface definitions
  5392. * @param val Change the values of tilt_en in reg CTRL10_C
  5393. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5394. *
  5395. */
  5396. int32_t lsm6ds3tr_c_wrist_tilt_sens_get(const stmdev_ctx_t *ctx,
  5397. uint8_t *val)
  5398. {
  5399. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  5400. int32_t ret;
  5401. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5402. (uint8_t *)&ctrl10_c, 1);
  5403. *val = ctrl10_c.wrist_tilt_en;
  5404. return ret;
  5405. }
  5406. /**
  5407. * @brief Absolute Wrist Tilt latency register (r/w).
  5408. * Absolute wrist tilt latency parameters.
  5409. * 1 LSB = 40 ms. Default value: 0Fh (600 ms).[set]
  5410. *
  5411. * @param ctx Read / write interface definitions
  5412. * @param buff Buffer that contains data to write
  5413. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5414. *
  5415. */
  5416. int32_t lsm6ds3tr_c_tilt_latency_set(const stmdev_ctx_t *ctx, uint8_t *buff)
  5417. {
  5418. int32_t ret;
  5419. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_B);
  5420. if (ret == 0)
  5421. {
  5422. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_A_WRIST_TILT_LAT, buff, 1);
  5423. if (ret == 0)
  5424. {
  5425. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5426. }
  5427. }
  5428. return ret;
  5429. }
  5430. /**
  5431. * @brief Absolute Wrist Tilt latency register (r/w).
  5432. * Absolute wrist tilt latency parameters.
  5433. * 1 LSB = 40 ms. Default value: 0Fh (600 ms).[get]
  5434. *
  5435. * @param ctx Read / write interface definitions
  5436. * @param buff Buffer that stores data read
  5437. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5438. *
  5439. */
  5440. int32_t lsm6ds3tr_c_tilt_latency_get(const stmdev_ctx_t *ctx, uint8_t *buff)
  5441. {
  5442. int32_t ret;
  5443. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_B);
  5444. if (ret == 0)
  5445. {
  5446. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_A_WRIST_TILT_LAT, buff, 1);
  5447. if (ret == 0)
  5448. {
  5449. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5450. }
  5451. }
  5452. return ret;
  5453. }
  5454. /**
  5455. * @brief Absolute Wrist Tilt threshold register(r/w).
  5456. * Absolute wrist tilt threshold parameters.
  5457. * 1 LSB = 15.625 mg.Default value: 20h (500 mg).[set]
  5458. *
  5459. * @param ctx Read / write interface definitions
  5460. * @param buff Buffer that contains data to write
  5461. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5462. *
  5463. */
  5464. int32_t lsm6ds3tr_c_tilt_threshold_set(const stmdev_ctx_t *ctx,
  5465. uint8_t *buff)
  5466. {
  5467. int32_t ret;
  5468. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_B);
  5469. if (ret == 0)
  5470. {
  5471. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_A_WRIST_TILT_THS, buff, 1);
  5472. if (ret == 0)
  5473. {
  5474. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5475. }
  5476. }
  5477. return ret;
  5478. }
  5479. /**
  5480. * @brief Absolute Wrist Tilt threshold register(r/w).
  5481. * Absolute wrist tilt threshold parameters.
  5482. * 1 LSB = 15.625 mg.Default value: 20h (500 mg).[get]
  5483. *
  5484. * @param ctx Read / write interface definitions
  5485. * @param buff Buffer that stores data read
  5486. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5487. *
  5488. */
  5489. int32_t lsm6ds3tr_c_tilt_threshold_get(const stmdev_ctx_t *ctx,
  5490. uint8_t *buff)
  5491. {
  5492. int32_t ret;
  5493. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_B);
  5494. if (ret == 0)
  5495. {
  5496. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_A_WRIST_TILT_THS, buff, 1);
  5497. if (ret == 0)
  5498. {
  5499. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5500. }
  5501. }
  5502. return ret;
  5503. }
  5504. /**
  5505. * @brief Absolute Wrist Tilt mask register (r/w).[set]
  5506. *
  5507. * @param ctx Read / write interface definitions
  5508. * @param val Registers A_WRIST_TILT_MASK
  5509. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5510. *
  5511. */
  5512. int32_t lsm6ds3tr_c_tilt_src_set(const stmdev_ctx_t *ctx,
  5513. lsm6ds3tr_c_a_wrist_tilt_mask_t *val)
  5514. {
  5515. int32_t ret;
  5516. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_B);
  5517. if (ret == 0)
  5518. {
  5519. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_A_WRIST_TILT_MASK,
  5520. (uint8_t *) val, 1);
  5521. if (ret == 0)
  5522. {
  5523. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5524. }
  5525. }
  5526. return ret;
  5527. }
  5528. /**
  5529. * @brief Absolute Wrist Tilt mask register (r/w).[get]
  5530. *
  5531. * @param ctx Read / write interface definitions
  5532. * @param val Registers A_WRIST_TILT_MASK
  5533. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5534. *
  5535. */
  5536. int32_t lsm6ds3tr_c_tilt_src_get(const stmdev_ctx_t *ctx,
  5537. lsm6ds3tr_c_a_wrist_tilt_mask_t *val)
  5538. {
  5539. int32_t ret;
  5540. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_B);
  5541. if (ret == 0)
  5542. {
  5543. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_A_WRIST_TILT_MASK,
  5544. (uint8_t *) val, 1);
  5545. if (ret == 0)
  5546. {
  5547. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5548. }
  5549. }
  5550. return ret;
  5551. }
  5552. /**
  5553. * @}
  5554. *
  5555. */
  5556. /**
  5557. * @defgroup LSM6DS3TR_C_ magnetometer_sensor
  5558. * @brief This section groups all the functions that manage additional
  5559. * magnetometer sensor.
  5560. * @{
  5561. *
  5562. */
  5563. /**
  5564. * @brief Enable soft-iron correction algorithm for magnetometer.[set]
  5565. *
  5566. * @param ctx Read / write interface definitions
  5567. * @param val Change the values of soft_en in reg CTRL9_XL
  5568. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5569. *
  5570. */
  5571. int32_t lsm6ds3tr_c_mag_soft_iron_set(const stmdev_ctx_t *ctx, uint8_t val)
  5572. {
  5573. lsm6ds3tr_c_ctrl9_xl_t ctrl9_xl;
  5574. int32_t ret;
  5575. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  5576. (uint8_t *)&ctrl9_xl, 1);
  5577. if (ret == 0)
  5578. {
  5579. ctrl9_xl.soft_en = val;
  5580. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  5581. (uint8_t *)&ctrl9_xl, 1);
  5582. }
  5583. return ret;
  5584. }
  5585. /**
  5586. * @brief Enable soft-iron correction algorithm for magnetometer.[get]
  5587. *
  5588. * @param ctx Read / write interface definitions
  5589. * @param val Change the values of soft_en in reg CTRL9_XL
  5590. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5591. *
  5592. */
  5593. int32_t lsm6ds3tr_c_mag_soft_iron_get(const stmdev_ctx_t *ctx, uint8_t *val)
  5594. {
  5595. lsm6ds3tr_c_ctrl9_xl_t ctrl9_xl;
  5596. int32_t ret;
  5597. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  5598. (uint8_t *)&ctrl9_xl, 1);
  5599. *val = ctrl9_xl.soft_en;
  5600. return ret;
  5601. }
  5602. /**
  5603. * @brief Enable hard-iron correction algorithm for magnetometer.[set]
  5604. *
  5605. * @param ctx Read / write interface definitions
  5606. * @param val Change the values of iron_en in reg MASTER_CONFIG
  5607. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5608. *
  5609. */
  5610. int32_t lsm6ds3tr_c_mag_hard_iron_set(const stmdev_ctx_t *ctx, uint8_t val)
  5611. {
  5612. lsm6ds3tr_c_master_config_t master_config;
  5613. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  5614. int32_t ret;
  5615. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  5616. (uint8_t *)&master_config, 1);
  5617. if (ret == 0)
  5618. {
  5619. master_config.iron_en = val;
  5620. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  5621. (uint8_t *)&master_config, 1);
  5622. if (ret == 0)
  5623. {
  5624. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5625. (uint8_t *)&ctrl10_c, 1);
  5626. if (ret == 0)
  5627. {
  5628. if (val != 0x00U)
  5629. {
  5630. ctrl10_c.func_en = val;
  5631. }
  5632. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5633. (uint8_t *)&ctrl10_c, 1);
  5634. }
  5635. }
  5636. }
  5637. return ret;
  5638. }
  5639. /**
  5640. * @brief Enable hard-iron correction algorithm for magnetometer.[get]
  5641. *
  5642. * @param ctx Read / write interface definitions
  5643. * @param val Change the values of iron_en in reg MASTER_CONFIG
  5644. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5645. *
  5646. */
  5647. int32_t lsm6ds3tr_c_mag_hard_iron_get(const stmdev_ctx_t *ctx, uint8_t *val)
  5648. {
  5649. lsm6ds3tr_c_master_config_t master_config;
  5650. int32_t ret;
  5651. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  5652. (uint8_t *)&master_config, 1);
  5653. *val = master_config.iron_en;
  5654. return ret;
  5655. }
  5656. /**
  5657. * @brief Soft iron 3x3 matrix. Value are expressed in sign-module format.
  5658. * (Es. SVVVVVVVb where S is the sign 0/+1/- and V is the value).[set]
  5659. *
  5660. * @param ctx Read / write interface definitions
  5661. * @param buff Buffer that contains data to write
  5662. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5663. *
  5664. */
  5665. int32_t lsm6ds3tr_c_mag_soft_iron_mat_set(const stmdev_ctx_t *ctx,
  5666. uint8_t *buff)
  5667. {
  5668. int32_t ret;
  5669. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5670. if (ret == 0)
  5671. {
  5672. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MAG_SI_XX, buff, 9);
  5673. if (ret == 0)
  5674. {
  5675. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5676. }
  5677. }
  5678. return ret;
  5679. }
  5680. /**
  5681. * @brief Soft iron 3x3 matrix. Value are expressed in sign-module format.
  5682. * (Es. SVVVVVVVb where S is the sign 0/+1/- and V is the value).[get]
  5683. *
  5684. * @param ctx Read / write interface definitions
  5685. * @param buff Buffer that stores data read
  5686. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5687. *
  5688. */
  5689. int32_t lsm6ds3tr_c_mag_soft_iron_mat_get(const stmdev_ctx_t *ctx,
  5690. uint8_t *buff)
  5691. {
  5692. int32_t ret;
  5693. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5694. if (ret == 0)
  5695. {
  5696. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MAG_SI_XX, buff, 9);
  5697. if (ret == 0)
  5698. {
  5699. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5700. }
  5701. }
  5702. return ret;
  5703. }
  5704. /**
  5705. * @brief Offset for hard-iron compensation register (r/w). The value is
  5706. * expressed as a 16-bit word in two’s complement.[set]
  5707. *
  5708. * @param ctx Read / write interface definitions
  5709. * @param buff Buffer that contains data to write
  5710. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5711. *
  5712. */
  5713. int32_t lsm6ds3tr_c_mag_offset_set(const stmdev_ctx_t *ctx, int16_t *val)
  5714. {
  5715. uint8_t buff[6];
  5716. int32_t ret;
  5717. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5718. if (ret == 0)
  5719. {
  5720. buff[1] = (uint8_t)((uint16_t)val[0] / 256U);
  5721. buff[0] = (uint8_t)((uint16_t)val[0] - (buff[1] * 256U));
  5722. buff[3] = (uint8_t)((uint16_t)val[1] / 256U);
  5723. buff[2] = (uint8_t)((uint16_t)val[1] - (buff[3] * 256U));
  5724. buff[5] = (uint8_t)((uint16_t)val[2] / 256U);
  5725. buff[4] = (uint8_t)((uint16_t)val[2] - (buff[5] * 256U));
  5726. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MAG_OFFX_L, buff, 6);
  5727. if (ret == 0)
  5728. {
  5729. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5730. }
  5731. }
  5732. return ret;
  5733. }
  5734. /**
  5735. * @brief Offset for hard-iron compensation register(r/w).
  5736. * The value is expressed as a 16-bit word in two’s complement.[get]
  5737. *
  5738. * @param ctx Read / write interface definitions
  5739. * @param buff Buffer that stores data read
  5740. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5741. *
  5742. */
  5743. int32_t lsm6ds3tr_c_mag_offset_get(const stmdev_ctx_t *ctx, int16_t *val)
  5744. {
  5745. uint8_t buff[6];
  5746. int32_t ret;
  5747. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5748. if (ret == 0)
  5749. {
  5750. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MAG_OFFX_L, buff, 6);
  5751. if (ret == 0)
  5752. {
  5753. val[0] = (int16_t)buff[1];
  5754. val[0] = (val[0] * 256) + (int16_t)buff[0];
  5755. val[1] = (int16_t)buff[3];
  5756. val[1] = (val[1] * 256) + (int16_t)buff[2];
  5757. val[2] = (int16_t)buff[5];
  5758. val[2] = (val[2] * 256) + (int16_t)buff[4];
  5759. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5760. }
  5761. }
  5762. return ret;
  5763. }
  5764. /**
  5765. * @}
  5766. *
  5767. */
  5768. /**
  5769. * @defgroup LSM6DS3TR_C_Sensor_hub
  5770. * @brief This section groups all the functions that manage the sensor
  5771. * hub functionality.
  5772. * @{
  5773. *
  5774. */
  5775. /**
  5776. * @brief Enable function.[set]
  5777. *
  5778. * @param ctx Read / write interface definitions
  5779. * @param val Change the values func_en
  5780. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5781. *
  5782. */
  5783. int32_t lsm6ds3tr_c_func_en_set(const stmdev_ctx_t *ctx, uint8_t val)
  5784. {
  5785. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  5786. int32_t ret;
  5787. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5788. (uint8_t *)&ctrl10_c, 1);
  5789. if (ret == 0)
  5790. {
  5791. ctrl10_c.func_en = val;
  5792. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5793. (uint8_t *)&ctrl10_c, 1);
  5794. }
  5795. return ret;
  5796. }
  5797. /**
  5798. * @brief Sensor synchronization time frame with the step of 500 ms and
  5799. * full range of 5s. Unsigned 8-bit.[set]
  5800. *
  5801. * @param ctx Read / write interface definitions
  5802. * @param val Change the values of tph in reg SENSOR_SYNC_TIME_FRAME
  5803. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5804. *
  5805. */
  5806. int32_t lsm6ds3tr_c_sh_sync_sens_frame_set(const stmdev_ctx_t *ctx,
  5807. uint8_t val)
  5808. {
  5809. lsm6ds3tr_c_sensor_sync_time_frame_t sensor_sync_time_frame;
  5810. int32_t ret;
  5811. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SENSOR_SYNC_TIME_FRAME,
  5812. (uint8_t *)&sensor_sync_time_frame, 1);
  5813. if (ret == 0)
  5814. {
  5815. sensor_sync_time_frame.tph = val;
  5816. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SENSOR_SYNC_TIME_FRAME,
  5817. (uint8_t *)&sensor_sync_time_frame, 1);
  5818. }
  5819. return ret;
  5820. }
  5821. /**
  5822. * @brief Sensor synchronization time frame with the step of 500 ms and
  5823. * full range of 5s. Unsigned 8-bit.[get]
  5824. *
  5825. * @param ctx Read / write interface definitions
  5826. * @param val Change the values of tph in reg SENSOR_SYNC_TIME_FRAME
  5827. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5828. *
  5829. */
  5830. int32_t lsm6ds3tr_c_sh_sync_sens_frame_get(const stmdev_ctx_t *ctx,
  5831. uint8_t *val)
  5832. {
  5833. lsm6ds3tr_c_sensor_sync_time_frame_t sensor_sync_time_frame;
  5834. int32_t ret;
  5835. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SENSOR_SYNC_TIME_FRAME,
  5836. (uint8_t *)&sensor_sync_time_frame, 1);
  5837. *val = sensor_sync_time_frame.tph;
  5838. return ret;
  5839. }
  5840. /**
  5841. * @brief Resolution ratio of error code for sensor synchronization.[set]
  5842. *
  5843. * @param ctx Read / write interface definitions
  5844. * @param val Change the values of rr in reg SENSOR_SYNC_RES_RATIO
  5845. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5846. *
  5847. */
  5848. int32_t lsm6ds3tr_c_sh_sync_sens_ratio_set(const stmdev_ctx_t *ctx,
  5849. lsm6ds3tr_c_rr_t val)
  5850. {
  5851. lsm6ds3tr_c_sensor_sync_res_ratio_t sensor_sync_res_ratio;
  5852. int32_t ret;
  5853. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SENSOR_SYNC_RES_RATIO,
  5854. (uint8_t *)&sensor_sync_res_ratio, 1);
  5855. if (ret == 0)
  5856. {
  5857. sensor_sync_res_ratio.rr = (uint8_t) val;
  5858. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SENSOR_SYNC_RES_RATIO,
  5859. (uint8_t *)&sensor_sync_res_ratio, 1);
  5860. }
  5861. return ret;
  5862. }
  5863. /**
  5864. * @brief Resolution ratio of error code for sensor synchronization.[get]
  5865. *
  5866. * @param ctx Read / write interface definitions
  5867. * @param val Get the values of rr in reg SENSOR_SYNC_RES_RATIO
  5868. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5869. *
  5870. */
  5871. int32_t lsm6ds3tr_c_sh_sync_sens_ratio_get(const stmdev_ctx_t *ctx,
  5872. lsm6ds3tr_c_rr_t *val)
  5873. {
  5874. lsm6ds3tr_c_sensor_sync_res_ratio_t sensor_sync_res_ratio;
  5875. int32_t ret;
  5876. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SENSOR_SYNC_RES_RATIO,
  5877. (uint8_t *)&sensor_sync_res_ratio, 1);
  5878. switch (sensor_sync_res_ratio.rr)
  5879. {
  5880. case LSM6DS3TR_C_RES_RATIO_2_11:
  5881. *val = LSM6DS3TR_C_RES_RATIO_2_11;
  5882. break;
  5883. case LSM6DS3TR_C_RES_RATIO_2_12:
  5884. *val = LSM6DS3TR_C_RES_RATIO_2_12;
  5885. break;
  5886. case LSM6DS3TR_C_RES_RATIO_2_13:
  5887. *val = LSM6DS3TR_C_RES_RATIO_2_13;
  5888. break;
  5889. case LSM6DS3TR_C_RES_RATIO_2_14:
  5890. *val = LSM6DS3TR_C_RES_RATIO_2_14;
  5891. break;
  5892. default:
  5893. *val = LSM6DS3TR_C_RES_RATIO_ND;
  5894. break;
  5895. }
  5896. return ret;
  5897. }
  5898. /**
  5899. * @brief Sensor hub I2C master enable.[set]
  5900. *
  5901. * @param ctx Read / write interface definitions
  5902. * @param val Change the values of master_on in reg MASTER_CONFIG
  5903. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5904. *
  5905. */
  5906. int32_t lsm6ds3tr_c_sh_master_set(const stmdev_ctx_t *ctx, uint8_t val)
  5907. {
  5908. lsm6ds3tr_c_master_config_t master_config;
  5909. int32_t ret;
  5910. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  5911. (uint8_t *)&master_config, 1);
  5912. if (ret == 0)
  5913. {
  5914. master_config.master_on = val;
  5915. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  5916. (uint8_t *)&master_config, 1);
  5917. }
  5918. return ret;
  5919. }
  5920. /**
  5921. * @brief Sensor hub I2C master enable.[get]
  5922. *
  5923. * @param ctx Read / write interface definitions
  5924. * @param val Change the values of master_on in reg MASTER_CONFIG
  5925. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5926. *
  5927. */
  5928. int32_t lsm6ds3tr_c_sh_master_get(const stmdev_ctx_t *ctx, uint8_t *val)
  5929. {
  5930. lsm6ds3tr_c_master_config_t master_config;
  5931. int32_t ret;
  5932. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  5933. (uint8_t *)&master_config, 1);
  5934. *val = master_config.master_on;
  5935. return ret;
  5936. }
  5937. /**
  5938. * @brief I2C interface pass-through.[set]
  5939. *
  5940. * @param ctx Read / write interface definitions
  5941. * @param val Change the values of pass_through_mode in reg MASTER_CONFIG
  5942. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5943. *
  5944. */
  5945. int32_t lsm6ds3tr_c_sh_pass_through_set(const stmdev_ctx_t *ctx,
  5946. uint8_t val)
  5947. {
  5948. lsm6ds3tr_c_master_config_t master_config;
  5949. int32_t ret;
  5950. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  5951. (uint8_t *)&master_config, 1);
  5952. if (ret == 0)
  5953. {
  5954. master_config.pass_through_mode = val;
  5955. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  5956. (uint8_t *)&master_config, 1);
  5957. }
  5958. return ret;
  5959. }
  5960. /**
  5961. * @brief I2C interface pass-through.[get]
  5962. *
  5963. * @param ctx Read / write interface definitions
  5964. * @param val Change the values of pass_through_mode in reg MASTER_CONFIG
  5965. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5966. *
  5967. */
  5968. int32_t lsm6ds3tr_c_sh_pass_through_get(const stmdev_ctx_t *ctx,
  5969. uint8_t *val)
  5970. {
  5971. lsm6ds3tr_c_master_config_t master_config;
  5972. int32_t ret;
  5973. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  5974. (uint8_t *)&master_config, 1);
  5975. *val = master_config.pass_through_mode;
  5976. return ret;
  5977. }
  5978. /**
  5979. * @brief Master I2C pull-up enable/disable.[set]
  5980. *
  5981. * @param ctx Read / write interface definitions
  5982. * @param val Change the values of pull_up_en in reg MASTER_CONFIG
  5983. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5984. *
  5985. */
  5986. int32_t lsm6ds3tr_c_sh_pin_mode_set(const stmdev_ctx_t *ctx,
  5987. lsm6ds3tr_c_pull_up_en_t val)
  5988. {
  5989. lsm6ds3tr_c_master_config_t master_config;
  5990. int32_t ret;
  5991. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  5992. (uint8_t *)&master_config, 1);
  5993. if (ret == 0)
  5994. {
  5995. master_config.pull_up_en = (uint8_t) val;
  5996. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  5997. (uint8_t *)&master_config, 1);
  5998. }
  5999. return ret;
  6000. }
  6001. /**
  6002. * @brief Master I2C pull-up enable/disable.[get]
  6003. *
  6004. * @param ctx Read / write interface definitions
  6005. * @param val Get the values of pull_up_en in reg MASTER_CONFIG
  6006. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6007. *
  6008. */
  6009. int32_t lsm6ds3tr_c_sh_pin_mode_get(const stmdev_ctx_t *ctx,
  6010. lsm6ds3tr_c_pull_up_en_t *val)
  6011. {
  6012. lsm6ds3tr_c_master_config_t master_config;
  6013. int32_t ret;
  6014. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  6015. (uint8_t *)&master_config, 1);
  6016. switch (master_config.pull_up_en)
  6017. {
  6018. case LSM6DS3TR_C_EXT_PULL_UP:
  6019. *val = LSM6DS3TR_C_EXT_PULL_UP;
  6020. break;
  6021. case LSM6DS3TR_C_INTERNAL_PULL_UP:
  6022. *val = LSM6DS3TR_C_INTERNAL_PULL_UP;
  6023. break;
  6024. default:
  6025. *val = LSM6DS3TR_C_SH_PIN_MODE;
  6026. break;
  6027. }
  6028. return ret;
  6029. }
  6030. /**
  6031. * @brief Sensor hub trigger signal selection.[set]
  6032. *
  6033. * @param ctx Read / write interface definitions
  6034. * @param val Change the values of start_config in reg MASTER_CONFIG
  6035. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6036. *
  6037. */
  6038. int32_t lsm6ds3tr_c_sh_syncro_mode_set(const stmdev_ctx_t *ctx,
  6039. lsm6ds3tr_c_start_config_t val)
  6040. {
  6041. lsm6ds3tr_c_master_config_t master_config;
  6042. int32_t ret;
  6043. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  6044. (uint8_t *)&master_config, 1);
  6045. if (ret == 0)
  6046. {
  6047. master_config.start_config = (uint8_t)val;
  6048. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  6049. (uint8_t *)&master_config, 1);
  6050. }
  6051. return ret;
  6052. }
  6053. /**
  6054. * @brief Sensor hub trigger signal selection.[get]
  6055. *
  6056. * @param ctx Read / write interface definitions
  6057. * @param val Get the values of start_config in reg MASTER_CONFIG
  6058. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6059. *
  6060. */
  6061. int32_t lsm6ds3tr_c_sh_syncro_mode_get(const stmdev_ctx_t *ctx,
  6062. lsm6ds3tr_c_start_config_t *val)
  6063. {
  6064. lsm6ds3tr_c_master_config_t master_config;
  6065. int32_t ret;
  6066. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  6067. (uint8_t *)&master_config, 1);
  6068. switch (master_config.start_config)
  6069. {
  6070. case LSM6DS3TR_C_XL_GY_DRDY:
  6071. *val = LSM6DS3TR_C_XL_GY_DRDY;
  6072. break;
  6073. case LSM6DS3TR_C_EXT_ON_INT2_PIN:
  6074. *val = LSM6DS3TR_C_EXT_ON_INT2_PIN;
  6075. break;
  6076. default:
  6077. *val = LSM6DS3TR_C_SH_SYNCRO_ND;
  6078. break;
  6079. }
  6080. return ret;
  6081. }
  6082. /**
  6083. * @brief Manage the Master DRDY signal on INT1 pad.[set]
  6084. *
  6085. * @param ctx Read / write interface definitions
  6086. * @param val Change the values of drdy_on_int1 in reg MASTER_CONFIG
  6087. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6088. *
  6089. */
  6090. int32_t lsm6ds3tr_c_sh_drdy_on_int1_set(const stmdev_ctx_t *ctx,
  6091. uint8_t val)
  6092. {
  6093. lsm6ds3tr_c_master_config_t master_config;
  6094. int32_t ret;
  6095. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  6096. (uint8_t *)&master_config, 1);
  6097. if (ret == 0)
  6098. {
  6099. master_config.drdy_on_int1 = val;
  6100. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  6101. (uint8_t *)&master_config, 1);
  6102. }
  6103. return ret;
  6104. }
  6105. /**
  6106. * @brief Manage the Master DRDY signal on INT1 pad.[get]
  6107. *
  6108. * @param ctx Read / write interface definitions
  6109. * @param val Change the values of drdy_on_int1 in reg MASTER_CONFIG
  6110. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6111. *
  6112. */
  6113. int32_t lsm6ds3tr_c_sh_drdy_on_int1_get(const stmdev_ctx_t *ctx,
  6114. uint8_t *val)
  6115. {
  6116. lsm6ds3tr_c_master_config_t master_config;
  6117. int32_t ret;
  6118. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  6119. (uint8_t *)&master_config, 1);
  6120. *val = master_config.drdy_on_int1;
  6121. return ret;
  6122. }
  6123. /**
  6124. * @brief Sensor hub output registers.[get]
  6125. *
  6126. * @param ctx Read / write interface definitions
  6127. * @param val Structure of registers from SENSORHUB1_REG
  6128. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6129. *
  6130. */
  6131. int32_t lsm6ds3tr_c_sh_read_data_raw_get(const stmdev_ctx_t *ctx,
  6132. lsm6ds3tr_c_emb_sh_read_t *val)
  6133. {
  6134. int32_t ret;
  6135. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SENSORHUB1_REG,
  6136. (uint8_t *) & (val->sh_byte_1), 12);
  6137. if (ret == 0)
  6138. {
  6139. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SENSORHUB13_REG,
  6140. (uint8_t *) & (val->sh_byte_13), 6);
  6141. }
  6142. return ret;
  6143. }
  6144. /**
  6145. * @brief Master command code used for stamping for sensor sync.[set]
  6146. *
  6147. * @param ctx Read / write interface definitions
  6148. * @param val Change the values of master_cmd_code in
  6149. * reg MASTER_CMD_CODE
  6150. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6151. *
  6152. */
  6153. int32_t lsm6ds3tr_c_sh_cmd_sens_sync_set(const stmdev_ctx_t *ctx,
  6154. uint8_t val)
  6155. {
  6156. lsm6ds3tr_c_master_cmd_code_t master_cmd_code;
  6157. int32_t ret;
  6158. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CMD_CODE,
  6159. (uint8_t *)&master_cmd_code, 1);
  6160. if (ret == 0)
  6161. {
  6162. master_cmd_code.master_cmd_code = val;
  6163. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MASTER_CMD_CODE,
  6164. (uint8_t *)&master_cmd_code, 1);
  6165. }
  6166. return ret;
  6167. }
  6168. /**
  6169. * @brief Master command code used for stamping for sensor sync.[get]
  6170. *
  6171. * @param ctx Read / write interface definitions
  6172. * @param val Change the values of master_cmd_code in
  6173. * reg MASTER_CMD_CODE
  6174. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6175. *
  6176. */
  6177. int32_t lsm6ds3tr_c_sh_cmd_sens_sync_get(const stmdev_ctx_t *ctx,
  6178. uint8_t *val)
  6179. {
  6180. lsm6ds3tr_c_master_cmd_code_t master_cmd_code;
  6181. int32_t ret;
  6182. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CMD_CODE,
  6183. (uint8_t *)&master_cmd_code, 1);
  6184. *val = master_cmd_code.master_cmd_code;
  6185. return ret;
  6186. }
  6187. /**
  6188. * @brief Error code used for sensor synchronization.[set]
  6189. *
  6190. * @param ctx Read / write interface definitions
  6191. * @param val Change the values of error_code in
  6192. * reg SENS_SYNC_SPI_ERROR_CODE.
  6193. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6194. *
  6195. */
  6196. int32_t lsm6ds3tr_c_sh_spi_sync_error_set(const stmdev_ctx_t *ctx,
  6197. uint8_t val)
  6198. {
  6199. lsm6ds3tr_c_sens_sync_spi_error_code_t sens_sync_spi_error_code;
  6200. int32_t ret;
  6201. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SENS_SYNC_SPI_ERROR_CODE,
  6202. (uint8_t *)&sens_sync_spi_error_code, 1);
  6203. if (ret == 0)
  6204. {
  6205. sens_sync_spi_error_code.error_code = val;
  6206. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SENS_SYNC_SPI_ERROR_CODE,
  6207. (uint8_t *)&sens_sync_spi_error_code, 1);
  6208. }
  6209. return ret;
  6210. }
  6211. /**
  6212. * @brief Error code used for sensor synchronization.[get]
  6213. *
  6214. * @param ctx Read / write interface definitions
  6215. * @param val Change the values of error_code in
  6216. * reg SENS_SYNC_SPI_ERROR_CODE.
  6217. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6218. *
  6219. */
  6220. int32_t lsm6ds3tr_c_sh_spi_sync_error_get(const stmdev_ctx_t *ctx,
  6221. uint8_t *val)
  6222. {
  6223. lsm6ds3tr_c_sens_sync_spi_error_code_t sens_sync_spi_error_code;
  6224. int32_t ret;
  6225. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SENS_SYNC_SPI_ERROR_CODE,
  6226. (uint8_t *)&sens_sync_spi_error_code, 1);
  6227. *val = sens_sync_spi_error_code.error_code;
  6228. return ret;
  6229. }
  6230. /**
  6231. * @brief Number of external sensors to be read by the sensor hub.[set]
  6232. *
  6233. * @param ctx Read / write interface definitions
  6234. * @param val Change the values of aux_sens_on in reg SLAVE0_CONFIG.
  6235. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6236. *
  6237. */
  6238. int32_t lsm6ds3tr_c_sh_num_of_dev_connected_set(const stmdev_ctx_t *ctx,
  6239. lsm6ds3tr_c_aux_sens_on_t val)
  6240. {
  6241. lsm6ds3tr_c_slave0_config_t slave0_config;
  6242. int32_t ret;
  6243. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6244. if (ret == 0)
  6245. {
  6246. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE0_CONFIG,
  6247. (uint8_t *)&slave0_config, 1);
  6248. if (ret == 0)
  6249. {
  6250. slave0_config.aux_sens_on = (uint8_t) val;
  6251. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLAVE0_CONFIG,
  6252. (uint8_t *)&slave0_config, 1);
  6253. if (ret == 0)
  6254. {
  6255. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6256. }
  6257. }
  6258. }
  6259. return ret;
  6260. }
  6261. /**
  6262. * @brief Number of external sensors to be read by the sensor hub.[get]
  6263. *
  6264. * @param ctx Read / write interface definitions
  6265. * @param val Get the values of aux_sens_on in reg SLAVE0_CONFIG.
  6266. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6267. *
  6268. */
  6269. int32_t lsm6ds3tr_c_sh_num_of_dev_connected_get(const stmdev_ctx_t *ctx,
  6270. lsm6ds3tr_c_aux_sens_on_t *val)
  6271. {
  6272. lsm6ds3tr_c_slave0_config_t slave0_config;
  6273. int32_t ret;
  6274. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6275. if (ret == 0)
  6276. {
  6277. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE0_CONFIG,
  6278. (uint8_t *)&slave0_config, 1);
  6279. if (ret == 0)
  6280. {
  6281. switch (slave0_config.aux_sens_on)
  6282. {
  6283. case LSM6DS3TR_C_SLV_0:
  6284. *val = LSM6DS3TR_C_SLV_0;
  6285. break;
  6286. case LSM6DS3TR_C_SLV_0_1:
  6287. *val = LSM6DS3TR_C_SLV_0_1;
  6288. break;
  6289. case LSM6DS3TR_C_SLV_0_1_2:
  6290. *val = LSM6DS3TR_C_SLV_0_1_2;
  6291. break;
  6292. case LSM6DS3TR_C_SLV_0_1_2_3:
  6293. *val = LSM6DS3TR_C_SLV_0_1_2_3;
  6294. break;
  6295. default:
  6296. *val = LSM6DS3TR_C_SLV_EN_ND;
  6297. break;
  6298. }
  6299. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6300. }
  6301. }
  6302. return ret;
  6303. }
  6304. /**
  6305. * @brief Configure slave 0 for perform a write.[set]
  6306. *
  6307. * @param ctx Read / write interface definitions
  6308. * @param val Structure that contain:
  6309. * - uint8_t slv_add; 8 bit i2c device address
  6310. * - uint8_t slv_subadd; 8 bit register device address
  6311. * - uint8_t slv_data; 8 bit data to write
  6312. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6313. *
  6314. */
  6315. int32_t lsm6ds3tr_c_sh_cfg_write(const stmdev_ctx_t *ctx,
  6316. lsm6ds3tr_c_sh_cfg_write_t *val)
  6317. {
  6318. lsm6ds3tr_c_slv0_add_t slv0_add;
  6319. int32_t ret;
  6320. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6321. if (ret == 0)
  6322. {
  6323. slv0_add.slave0_add = val->slv0_add;
  6324. slv0_add.rw_0 = 0;
  6325. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLV0_ADD,
  6326. (uint8_t *)&slv0_add, 1);
  6327. if (ret == 0)
  6328. {
  6329. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLV0_SUBADD,
  6330. &(val->slv0_subadd), 1);
  6331. if (ret == 0)
  6332. {
  6333. ret = lsm6ds3tr_c_write_reg(ctx,
  6334. LSM6DS3TR_C_DATAWRITE_SRC_MODE_SUB_SLV0,
  6335. &(val->slv0_data), 1);
  6336. if (ret == 0)
  6337. {
  6338. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6339. }
  6340. }
  6341. }
  6342. }
  6343. return ret;
  6344. }
  6345. /**
  6346. * @brief Configure slave 0 for perform a read.[get]
  6347. *
  6348. * @param ctx Read / write interface definitions
  6349. * @param val Structure that contain:
  6350. * - uint8_t slv_add; 8 bit i2c device address
  6351. * - uint8_t slv_subadd; 8 bit register device address
  6352. * - uint8_t slv_len; num of bit to read
  6353. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6354. *
  6355. */
  6356. int32_t lsm6ds3tr_c_sh_slv0_cfg_read(const stmdev_ctx_t *ctx,
  6357. lsm6ds3tr_c_sh_cfg_read_t *val)
  6358. {
  6359. lsm6ds3tr_c_slave0_config_t slave0_config;
  6360. lsm6ds3tr_c_slv0_add_t slv0_add;
  6361. int32_t ret;
  6362. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6363. if (ret == 0)
  6364. {
  6365. slv0_add.slave0_add = val->slv_add;
  6366. slv0_add.rw_0 = 1;
  6367. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLV0_ADD,
  6368. (uint8_t *)&slv0_add, 1);
  6369. if (ret == 0)
  6370. {
  6371. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLV0_SUBADD,
  6372. &(val->slv_subadd), 1);
  6373. if (ret == 0)
  6374. {
  6375. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE0_CONFIG,
  6376. (uint8_t *)&slave0_config, 1);
  6377. slave0_config.slave0_numop = val->slv_len;
  6378. if (ret == 0)
  6379. {
  6380. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLAVE0_CONFIG,
  6381. (uint8_t *)&slave0_config, 1);
  6382. if (ret == 0)
  6383. {
  6384. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6385. }
  6386. }
  6387. }
  6388. }
  6389. }
  6390. return ret;
  6391. }
  6392. /**
  6393. * @brief Configure slave 1 for perform a read.[get]
  6394. *
  6395. * @param ctx Read / write interface definitions
  6396. * @param val Structure that contain:
  6397. * - uint8_t slv_add; 8 bit i2c device address
  6398. * - uint8_t slv_subadd; 8 bit register device address
  6399. * - uint8_t slv_len; num of bit to read
  6400. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6401. *
  6402. */
  6403. int32_t lsm6ds3tr_c_sh_slv1_cfg_read(const stmdev_ctx_t *ctx,
  6404. lsm6ds3tr_c_sh_cfg_read_t *val)
  6405. {
  6406. lsm6ds3tr_c_slave1_config_t slave1_config;
  6407. lsm6ds3tr_c_slv1_add_t slv1_add;
  6408. int32_t ret;
  6409. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6410. if (ret == 0)
  6411. {
  6412. slv1_add.slave1_add = val->slv_add;
  6413. slv1_add.r_1 = 1;
  6414. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLV1_ADD,
  6415. (uint8_t *)&slv1_add, 1);
  6416. if (ret == 0)
  6417. {
  6418. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLV1_SUBADD,
  6419. &(val->slv_subadd), 1);
  6420. if (ret == 0)
  6421. {
  6422. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE1_CONFIG,
  6423. (uint8_t *)&slave1_config, 1);
  6424. slave1_config.slave1_numop = val->slv_len;
  6425. if (ret == 0)
  6426. {
  6427. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLAVE1_CONFIG,
  6428. (uint8_t *)&slave1_config, 1);
  6429. if (ret == 0)
  6430. {
  6431. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6432. }
  6433. }
  6434. }
  6435. }
  6436. }
  6437. return ret;
  6438. }
  6439. /**
  6440. * @brief Configure slave 2 for perform a read.[get]
  6441. *
  6442. * @param ctx Read / write interface definitions
  6443. * @param val Structure that contain:
  6444. * - uint8_t slv_add; 8 bit i2c device address
  6445. * - uint8_t slv_subadd; 8 bit register device address
  6446. * - uint8_t slv_len; num of bit to read
  6447. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6448. *
  6449. */
  6450. int32_t lsm6ds3tr_c_sh_slv2_cfg_read(const stmdev_ctx_t *ctx,
  6451. lsm6ds3tr_c_sh_cfg_read_t *val)
  6452. {
  6453. lsm6ds3tr_c_slv2_add_t slv2_add;
  6454. lsm6ds3tr_c_slave2_config_t slave2_config;
  6455. int32_t ret;
  6456. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6457. if (ret == 0)
  6458. {
  6459. slv2_add.slave2_add = val->slv_add;
  6460. slv2_add.r_2 = 1;
  6461. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLV2_ADD,
  6462. (uint8_t *)&slv2_add, 1);
  6463. if (ret == 0)
  6464. {
  6465. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLV2_SUBADD,
  6466. &(val->slv_subadd), 1);
  6467. if (ret == 0)
  6468. {
  6469. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE2_CONFIG,
  6470. (uint8_t *)&slave2_config, 1);
  6471. if (ret == 0)
  6472. {
  6473. slave2_config.slave2_numop = val->slv_len;
  6474. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLAVE2_CONFIG,
  6475. (uint8_t *)&slave2_config, 1);
  6476. if (ret == 0)
  6477. {
  6478. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6479. }
  6480. }
  6481. }
  6482. }
  6483. }
  6484. return ret;
  6485. }
  6486. /**
  6487. * @brief Configure slave 3 for perform a read.[get]
  6488. *
  6489. * @param ctx Read / write interface definitions
  6490. * @param val Structure that contain:
  6491. * - uint8_t slv_add; 8 bit i2c device address
  6492. * - uint8_t slv_subadd; 8 bit register device address
  6493. * - uint8_t slv_len; num of bit to read
  6494. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6495. *
  6496. */
  6497. int32_t lsm6ds3tr_c_sh_slv3_cfg_read(const stmdev_ctx_t *ctx,
  6498. lsm6ds3tr_c_sh_cfg_read_t *val)
  6499. {
  6500. lsm6ds3tr_c_slave3_config_t slave3_config;
  6501. lsm6ds3tr_c_slv3_add_t slv3_add;
  6502. int32_t ret;
  6503. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6504. if (ret == 0)
  6505. {
  6506. slv3_add.slave3_add = val->slv_add;
  6507. slv3_add.r_3 = 1;
  6508. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLV3_ADD,
  6509. (uint8_t *)&slv3_add, 1);
  6510. if (ret == 0)
  6511. {
  6512. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLV3_SUBADD,
  6513. (uint8_t *) & (val->slv_subadd), 1);
  6514. if (ret == 0)
  6515. {
  6516. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE3_CONFIG,
  6517. (uint8_t *)&slave3_config, 1);
  6518. if (ret == 0)
  6519. {
  6520. slave3_config.slave3_numop = val->slv_len;
  6521. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLAVE3_CONFIG,
  6522. (uint8_t *)&slave3_config, 1);
  6523. if (ret == 0)
  6524. {
  6525. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6526. }
  6527. }
  6528. }
  6529. }
  6530. }
  6531. return ret;
  6532. }
  6533. /**
  6534. * @brief Decimation of read operation on Slave 0 starting from the
  6535. * sensor hub trigger.[set]
  6536. *
  6537. * @param ctx Read / write interface definitions
  6538. * @param val Change the values of slave0_rate in reg SLAVE0_CONFIG
  6539. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6540. *
  6541. */
  6542. int32_t lsm6ds3tr_c_sh_slave_0_dec_set(const stmdev_ctx_t *ctx,
  6543. lsm6ds3tr_c_slave0_rate_t val)
  6544. {
  6545. lsm6ds3tr_c_slave0_config_t slave0_config;
  6546. int32_t ret;
  6547. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6548. if (ret == 0)
  6549. {
  6550. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE0_CONFIG,
  6551. (uint8_t *)&slave0_config, 1);
  6552. if (ret == 0)
  6553. {
  6554. slave0_config.slave0_rate = (uint8_t) val;
  6555. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLAVE0_CONFIG,
  6556. (uint8_t *)&slave0_config, 1);
  6557. if (ret == 0)
  6558. {
  6559. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6560. }
  6561. }
  6562. }
  6563. return ret;
  6564. }
  6565. /**
  6566. * @brief Decimation of read operation on Slave 0 starting from the
  6567. * sensor hub trigger.[get]
  6568. *
  6569. * @param ctx Read / write interface definitions
  6570. * @param val Get the values of slave0_rate in reg SLAVE0_CONFIG
  6571. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6572. *
  6573. */
  6574. int32_t lsm6ds3tr_c_sh_slave_0_dec_get(const stmdev_ctx_t *ctx,
  6575. lsm6ds3tr_c_slave0_rate_t *val)
  6576. {
  6577. lsm6ds3tr_c_slave0_config_t slave0_config;
  6578. int32_t ret;
  6579. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6580. if (ret == 0)
  6581. {
  6582. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE0_CONFIG,
  6583. (uint8_t *)&slave0_config, 1);
  6584. if (ret == 0)
  6585. {
  6586. switch (slave0_config.slave0_rate)
  6587. {
  6588. case LSM6DS3TR_C_SL0_NO_DEC:
  6589. *val = LSM6DS3TR_C_SL0_NO_DEC;
  6590. break;
  6591. case LSM6DS3TR_C_SL0_DEC_2:
  6592. *val = LSM6DS3TR_C_SL0_DEC_2;
  6593. break;
  6594. case LSM6DS3TR_C_SL0_DEC_4:
  6595. *val = LSM6DS3TR_C_SL0_DEC_4;
  6596. break;
  6597. case LSM6DS3TR_C_SL0_DEC_8:
  6598. *val = LSM6DS3TR_C_SL0_DEC_8;
  6599. break;
  6600. default:
  6601. *val = LSM6DS3TR_C_SL0_DEC_ND;
  6602. break;
  6603. }
  6604. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6605. }
  6606. }
  6607. return ret;
  6608. }
  6609. /**
  6610. * @brief Slave 0 write operation is performed only at the first sensor
  6611. * hub cycle.
  6612. * This is effective if the Aux_sens_on[1:0] field in
  6613. * SLAVE0_CONFIG(04h) is set to a value other than 00.[set]
  6614. *
  6615. * @param ctx Read / write interface definitions
  6616. * @param val Change the values of write_once in reg SLAVE1_CONFIG
  6617. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6618. *
  6619. */
  6620. int32_t lsm6ds3tr_c_sh_write_mode_set(const stmdev_ctx_t *ctx,
  6621. lsm6ds3tr_c_write_once_t val)
  6622. {
  6623. lsm6ds3tr_c_slave1_config_t slave1_config;
  6624. int32_t ret;
  6625. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6626. if (ret == 0)
  6627. {
  6628. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE1_CONFIG,
  6629. (uint8_t *)&slave1_config, 1);
  6630. slave1_config.write_once = (uint8_t) val;
  6631. if (ret == 0)
  6632. {
  6633. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLAVE1_CONFIG,
  6634. (uint8_t *)&slave1_config, 1);
  6635. if (ret == 0)
  6636. {
  6637. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6638. }
  6639. }
  6640. }
  6641. return ret;
  6642. }
  6643. /**
  6644. * @brief Slave 0 write operation is performed only at the first sensor
  6645. * hub cycle.
  6646. * This is effective if the Aux_sens_on[1:0] field in
  6647. * SLAVE0_CONFIG(04h) is set to a value other than 00.[get]
  6648. *
  6649. * @param ctx Read / write interface definitions
  6650. * @param val Get the values of write_once in reg SLAVE1_CONFIG
  6651. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6652. *
  6653. */
  6654. int32_t lsm6ds3tr_c_sh_write_mode_get(const stmdev_ctx_t *ctx,
  6655. lsm6ds3tr_c_write_once_t *val)
  6656. {
  6657. lsm6ds3tr_c_slave1_config_t slave1_config;
  6658. int32_t ret;
  6659. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6660. if (ret == 0)
  6661. {
  6662. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE1_CONFIG,
  6663. (uint8_t *)&slave1_config, 1);
  6664. if (ret == 0)
  6665. {
  6666. switch (slave1_config.write_once)
  6667. {
  6668. case LSM6DS3TR_C_EACH_SH_CYCLE:
  6669. *val = LSM6DS3TR_C_EACH_SH_CYCLE;
  6670. break;
  6671. case LSM6DS3TR_C_ONLY_FIRST_CYCLE:
  6672. *val = LSM6DS3TR_C_ONLY_FIRST_CYCLE;
  6673. break;
  6674. default:
  6675. *val = LSM6DS3TR_C_SH_WR_MODE_ND;
  6676. break;
  6677. }
  6678. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6679. }
  6680. }
  6681. return ret;
  6682. }
  6683. /**
  6684. * @brief Decimation of read operation on Slave 1 starting from the
  6685. * sensor hub trigger.[set]
  6686. *
  6687. * @param ctx Read / write interface definitions
  6688. * @param val Change the values of slave1_rate in reg SLAVE1_CONFIG
  6689. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6690. *
  6691. */
  6692. int32_t lsm6ds3tr_c_sh_slave_1_dec_set(const stmdev_ctx_t *ctx,
  6693. lsm6ds3tr_c_slave1_rate_t val)
  6694. {
  6695. lsm6ds3tr_c_slave1_config_t slave1_config;
  6696. int32_t ret;
  6697. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6698. if (ret == 0)
  6699. {
  6700. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE1_CONFIG,
  6701. (uint8_t *)&slave1_config, 1);
  6702. if (ret == 0)
  6703. {
  6704. slave1_config.slave1_rate = (uint8_t) val;
  6705. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLAVE1_CONFIG,
  6706. (uint8_t *)&slave1_config, 1);
  6707. if (ret == 0)
  6708. {
  6709. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6710. }
  6711. }
  6712. }
  6713. return ret;
  6714. }
  6715. /**
  6716. * @brief Decimation of read operation on Slave 1 starting from the
  6717. * sensor hub trigger.[get]
  6718. *
  6719. * @param ctx Read / write interface definitions reg SLAVE1_CONFIG
  6720. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6721. *
  6722. */
  6723. int32_t lsm6ds3tr_c_sh_slave_1_dec_get(const stmdev_ctx_t *ctx,
  6724. lsm6ds3tr_c_slave1_rate_t *val)
  6725. {
  6726. lsm6ds3tr_c_slave1_config_t slave1_config;
  6727. int32_t ret;
  6728. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6729. if (ret == 0)
  6730. {
  6731. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE1_CONFIG,
  6732. (uint8_t *)&slave1_config, 1);
  6733. if (ret == 0)
  6734. {
  6735. switch (slave1_config.slave1_rate)
  6736. {
  6737. case LSM6DS3TR_C_SL1_NO_DEC:
  6738. *val = LSM6DS3TR_C_SL1_NO_DEC;
  6739. break;
  6740. case LSM6DS3TR_C_SL1_DEC_2:
  6741. *val = LSM6DS3TR_C_SL1_DEC_2;
  6742. break;
  6743. case LSM6DS3TR_C_SL1_DEC_4:
  6744. *val = LSM6DS3TR_C_SL1_DEC_4;
  6745. break;
  6746. case LSM6DS3TR_C_SL1_DEC_8:
  6747. *val = LSM6DS3TR_C_SL1_DEC_8;
  6748. break;
  6749. default:
  6750. *val = LSM6DS3TR_C_SL1_DEC_ND;
  6751. break;
  6752. }
  6753. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6754. }
  6755. }
  6756. return ret;
  6757. }
  6758. /**
  6759. * @brief Decimation of read operation on Slave 2 starting from the
  6760. * sensor hub trigger.[set]
  6761. *
  6762. * @param ctx Read / write interface definitions
  6763. * @param val Change the values of slave2_rate in reg SLAVE2_CONFIG
  6764. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6765. *
  6766. */
  6767. int32_t lsm6ds3tr_c_sh_slave_2_dec_set(const stmdev_ctx_t *ctx,
  6768. lsm6ds3tr_c_slave2_rate_t val)
  6769. {
  6770. lsm6ds3tr_c_slave2_config_t slave2_config;
  6771. int32_t ret;
  6772. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6773. if (ret == 0)
  6774. {
  6775. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE2_CONFIG,
  6776. (uint8_t *)&slave2_config, 1);
  6777. if (ret == 0)
  6778. {
  6779. slave2_config.slave2_rate = (uint8_t) val;
  6780. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLAVE2_CONFIG,
  6781. (uint8_t *)&slave2_config, 1);
  6782. if (ret == 0)
  6783. {
  6784. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6785. }
  6786. }
  6787. }
  6788. return ret;
  6789. }
  6790. /**
  6791. * @brief Decimation of read operation on Slave 2 starting from the
  6792. * sensor hub trigger.[get]
  6793. *
  6794. * @param ctx Read / write interface definitions
  6795. * @param val Get the values of slave2_rate in reg SLAVE2_CONFIG
  6796. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6797. *
  6798. */
  6799. int32_t lsm6ds3tr_c_sh_slave_2_dec_get(const stmdev_ctx_t *ctx,
  6800. lsm6ds3tr_c_slave2_rate_t *val)
  6801. {
  6802. lsm6ds3tr_c_slave2_config_t slave2_config;
  6803. int32_t ret;
  6804. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6805. if (ret == 0)
  6806. {
  6807. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE2_CONFIG,
  6808. (uint8_t *)&slave2_config, 1);
  6809. if (ret == 0)
  6810. {
  6811. switch (slave2_config.slave2_rate)
  6812. {
  6813. case LSM6DS3TR_C_SL2_NO_DEC:
  6814. *val = LSM6DS3TR_C_SL2_NO_DEC;
  6815. break;
  6816. case LSM6DS3TR_C_SL2_DEC_2:
  6817. *val = LSM6DS3TR_C_SL2_DEC_2;
  6818. break;
  6819. case LSM6DS3TR_C_SL2_DEC_4:
  6820. *val = LSM6DS3TR_C_SL2_DEC_4;
  6821. break;
  6822. case LSM6DS3TR_C_SL2_DEC_8:
  6823. *val = LSM6DS3TR_C_SL2_DEC_8;
  6824. break;
  6825. default:
  6826. *val = LSM6DS3TR_C_SL2_DEC_ND;
  6827. break;
  6828. }
  6829. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6830. }
  6831. }
  6832. return ret;
  6833. }
  6834. /**
  6835. * @brief Decimation of read operation on Slave 3 starting from the
  6836. * sensor hub trigger.[set]
  6837. *
  6838. * @param ctx Read / write interface definitions
  6839. * @param val Change the values of slave3_rate in reg SLAVE3_CONFIG
  6840. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6841. *
  6842. */
  6843. int32_t lsm6ds3tr_c_sh_slave_3_dec_set(const stmdev_ctx_t *ctx,
  6844. lsm6ds3tr_c_slave3_rate_t val)
  6845. {
  6846. lsm6ds3tr_c_slave3_config_t slave3_config;
  6847. int32_t ret;
  6848. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6849. if (ret == 0)
  6850. {
  6851. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE3_CONFIG,
  6852. (uint8_t *)&slave3_config, 1);
  6853. slave3_config.slave3_rate = (uint8_t)val;
  6854. if (ret == 0)
  6855. {
  6856. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLAVE3_CONFIG,
  6857. (uint8_t *)&slave3_config, 1);
  6858. if (ret == 0)
  6859. {
  6860. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6861. }
  6862. }
  6863. }
  6864. return ret;
  6865. }
  6866. /**
  6867. * @brief Decimation of read operation on Slave 3 starting from the
  6868. * sensor hub trigger.[get]
  6869. *
  6870. * @param ctx Read / write interface definitions
  6871. * @param val Get the values of slave3_rate in reg SLAVE3_CONFIG.
  6872. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6873. *
  6874. */
  6875. int32_t lsm6ds3tr_c_sh_slave_3_dec_get(const stmdev_ctx_t *ctx,
  6876. lsm6ds3tr_c_slave3_rate_t *val)
  6877. {
  6878. lsm6ds3tr_c_slave3_config_t slave3_config;
  6879. int32_t ret;
  6880. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6881. if (ret == 0)
  6882. {
  6883. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE3_CONFIG,
  6884. (uint8_t *)&slave3_config, 1);
  6885. if (ret == 0)
  6886. {
  6887. switch (slave3_config.slave3_rate)
  6888. {
  6889. case LSM6DS3TR_C_SL3_NO_DEC:
  6890. *val = LSM6DS3TR_C_SL3_NO_DEC;
  6891. break;
  6892. case LSM6DS3TR_C_SL3_DEC_2:
  6893. *val = LSM6DS3TR_C_SL3_DEC_2;
  6894. break;
  6895. case LSM6DS3TR_C_SL3_DEC_4:
  6896. *val = LSM6DS3TR_C_SL3_DEC_4;
  6897. break;
  6898. case LSM6DS3TR_C_SL3_DEC_8:
  6899. *val = LSM6DS3TR_C_SL3_DEC_8;
  6900. break;
  6901. default:
  6902. *val = LSM6DS3TR_C_SL3_DEC_ND;
  6903. break;
  6904. }
  6905. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6906. }
  6907. }
  6908. return ret;
  6909. }
  6910. /**
  6911. * @}
  6912. *
  6913. */
  6914. /**
  6915. * @}
  6916. *
  6917. */
  6918. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/