lsm6ds3tr_c_reg.c 202 KB

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